@@ -35,18 +35,22 @@ struct bitmap *bitmap_new(void)
return bitmap_word_alloc(32);
}
-void bitmap_set(struct bitmap *self, size_t pos)
+static void bitmap_grow(struct bitmap *self, size_t word_alloc)
{
- size_t block = EWAH_BLOCK(pos);
-
- if (block >= self->word_alloc) {
+ if (word_alloc > self->word_alloc) {
size_t old_size = self->word_alloc;
- self->word_alloc = block ? block * 2 : 1;
+ self->word_alloc = word_alloc * 2;
REALLOC_ARRAY(self->words, self->word_alloc);
memset(self->words + old_size, 0x0,
(self->word_alloc - old_size) * sizeof(eword_t));
}
+}
+void bitmap_set(struct bitmap *self, size_t pos)
+{
+ size_t block = EWAH_BLOCK(pos);
+
+ bitmap_grow(self, block + 1);
self->words[block] |= EWAH_MASK(pos);
}