]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bitmap: add bitmap_unset() function
authorJeff King <peff@peff.net>
Fri, 14 Feb 2020 18:22:34 +0000 (13:22 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Feb 2020 18:46:22 +0000 (10:46 -0800)
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>
ewah/bitmap.c
ewah/ewok.h

index 52f1178db4ce35103545a3e1ee00a3000b08eb90..1c31b3e249aeb59963f13babb3757340dd5dc140 100644 (file)
@@ -45,6 +45,14 @@ void bitmap_set(struct bitmap *self, size_t pos)
        self->words[block] |= EWAH_MASK(pos);
 }
 
+void bitmap_unset(struct bitmap *self, size_t pos)
+{
+       size_t block = EWAH_BLOCK(pos);
+
+       if (block < self->word_alloc)
+               self->words[block] &= ~EWAH_MASK(pos);
+}
+
 int bitmap_get(struct bitmap *self, size_t pos)
 {
        size_t block = EWAH_BLOCK(pos);
index 84b2a29faa0c57410168ad5afb2dbaa7a49ddd60..59f4ef7c4fa4ef44cc898b21b990260d6b4fd9fe 100644 (file)
@@ -173,6 +173,7 @@ struct bitmap {
 
 struct bitmap *bitmap_new(void);
 void bitmap_set(struct bitmap *self, size_t pos);
+void bitmap_unset(struct bitmap *self, size_t pos);
 int bitmap_get(struct bitmap *self, size_t pos);
 void bitmap_reset(struct bitmap *self);
 void bitmap_free(struct bitmap *self);