Skip to content

Commit cc4aa28

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2aaeb9a commit cc4aa28

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ewah/bitmap.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ void bitmap_set(struct bitmap *self, size_t pos)
4545
self->words[block] |= EWAH_MASK(pos);
4646
}
4747

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+
4856
int bitmap_get(struct bitmap *self, size_t pos)
4957
{
5058
size_t block = EWAH_BLOCK(pos);

ewah/ewok.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct bitmap {
173173

174174
struct bitmap *bitmap_new(void);
175175
void bitmap_set(struct bitmap *self, size_t pos);
176+
void bitmap_unset(struct bitmap *self, size_t pos);
176177
int bitmap_get(struct bitmap *self, size_t pos);
177178
void bitmap_reset(struct bitmap *self);
178179
void bitmap_free(struct bitmap *self);

0 commit comments

Comments
 (0)