diff options
Diffstat (limited to 'ewah/bitmap.c')
-rw-r--r-- | ewah/bitmap.c | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/ewah/bitmap.c b/ewah/bitmap.c index 710e58c1bf..756bdd050e 100644 --- a/ewah/bitmap.c +++ b/ewah/bitmap.c @@ -14,53 +14,50 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * along with this program; if not, see <http://www.gnu.org/licenses/>. */ -#include "git-compat-util.h" +#include "cache.h" #include "ewok.h" -#define MASK(x) ((eword_t)1 << (x % BITS_IN_WORD)) -#define BLOCK(x) (x / BITS_IN_WORD) +#define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD)) +#define EWAH_BLOCK(x) (x / BITS_IN_EWORD) struct bitmap *bitmap_new(void) { - struct bitmap *bitmap = ewah_malloc(sizeof(struct bitmap)); - bitmap->words = ewah_calloc(32, sizeof(eword_t)); + struct bitmap *bitmap = xmalloc(sizeof(struct bitmap)); + bitmap->words = xcalloc(32, sizeof(eword_t)); bitmap->word_alloc = 32; return bitmap; } void bitmap_set(struct bitmap *self, size_t pos) { - size_t block = BLOCK(pos); + size_t block = EWAH_BLOCK(pos); if (block >= self->word_alloc) { size_t old_size = self->word_alloc; self->word_alloc = block * 2; - self->words = ewah_realloc(self->words, - self->word_alloc * sizeof(eword_t)); - + REALLOC_ARRAY(self->words, self->word_alloc); memset(self->words + old_size, 0x0, (self->word_alloc - old_size) * sizeof(eword_t)); } - self->words[block] |= MASK(pos); + self->words[block] |= EWAH_MASK(pos); } void bitmap_clear(struct bitmap *self, size_t pos) { - size_t block = BLOCK(pos); + size_t block = EWAH_BLOCK(pos); if (block < self->word_alloc) - self->words[block] &= ~MASK(pos); + self->words[block] &= ~EWAH_MASK(pos); } int bitmap_get(struct bitmap *self, size_t pos) { - size_t block = BLOCK(pos); + size_t block = EWAH_BLOCK(pos); return block < self->word_alloc && - (self->words[block] & MASK(pos)) != 0; + (self->words[block] & EWAH_MASK(pos)) != 0; } struct ewah_bitmap *bitmap_to_ewah(struct bitmap *bitmap) @@ -100,12 +97,7 @@ struct bitmap *ewah_to_bitmap(struct ewah_bitmap *ewah) ewah_iterator_init(&it, ewah); while (ewah_iterator_next(&blowup, &it)) { - if (i >= bitmap->word_alloc) { - bitmap->word_alloc *= 1.5; - bitmap->words = ewah_realloc( - bitmap->words, bitmap->word_alloc * sizeof(eword_t)); - } - + ALLOC_GROW(bitmap->words, i + 1, bitmap->word_alloc); bitmap->words[i++] = blowup; } @@ -127,15 +119,14 @@ void bitmap_and_not(struct bitmap *self, struct bitmap *other) void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other) { size_t original_size = self->word_alloc; - size_t other_final = (other->bit_size / BITS_IN_WORD) + 1; + size_t other_final = (other->bit_size / BITS_IN_EWORD) + 1; size_t i = 0; struct ewah_iterator it; eword_t word; if (self->word_alloc < other_final) { self->word_alloc = other_final; - self->words = ewah_realloc(self->words, - self->word_alloc * sizeof(eword_t)); + REALLOC_ARRAY(self->words, self->word_alloc); memset(self->words + original_size, 0x0, (self->word_alloc - original_size) * sizeof(eword_t)); } @@ -155,17 +146,17 @@ void bitmap_each_bit(struct bitmap *self, ewah_callback callback, void *data) uint32_t offset; if (word == (eword_t)~0) { - for (offset = 0; offset < BITS_IN_WORD; ++offset) + for (offset = 0; offset < BITS_IN_EWORD; ++offset) callback(pos++, data); } else { - for (offset = 0; offset < BITS_IN_WORD; ++offset) { + for (offset = 0; offset < BITS_IN_EWORD; ++offset) { if ((word >> offset) == 0) break; offset += ewah_bit_ctz64(word >> offset); callback(pos + offset, data); } - pos += BITS_IN_WORD; + pos += BITS_IN_EWORD; } } } |