@matheusbsbs / matheus-bagliano / commits / cc4aa28506
Fork 0

bitmap: add bitmap_unset() function

We've never needed to unset an individual bit in a bitmap until now. Typically they start with all bits unset and we bitmap_set() them, or we are applying another bitmap as a mask. But the easiest way to apply an object filter to a bitmap result will be to unset the individual bits. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 14, 2020 at 13:22 UTC cc4aa28506e079e0c17cfbe78743530795803ea8
2 files changed +9
ewah/bitmap.c
+8
@@ -45,6 +45,14 @@ void bitmap_set(struct bitmap *self, size_t pos)
45 self->words[block] |= EWAH_MASK(pos);
46 }
47
48 +void bitmap_unset(struct bitmap *self, size_t pos)
49 +{
50 + size_t block = EWAH_BLOCK(pos);
51 +
52 + if (block < self->word_alloc)
53 + self->words[block] &= ~EWAH_MASK(pos);
54 +}
55 +
56 int bitmap_get(struct bitmap *self, size_t pos)
57 {
58 size_t block = EWAH_BLOCK(pos);
ewah/ewok.h
+1
@@ -173,6 +173,7 @@ struct bitmap {
173
174 struct bitmap *bitmap_new(void);
175 void bitmap_set(struct bitmap *self, size_t pos);
176 +void bitmap_unset(struct bitmap *self, size_t pos);
177 int bitmap_get(struct bitmap *self, size_t pos);
178 void bitmap_reset(struct bitmap *self);
179 void bitmap_free(struct bitmap *self);