Skip to content

Commit e5d48bf

Browse files
ttaylorrgitster
authored andcommitted
ewah: implement bitmap_is_empty()
In a future commit, we will want to check whether or not a bitmap has any bits set in any of its words. The best way to do this (prior to the existence of this patch) is to call `bitmap_popcount()` and check whether the result is non-zero. But this is semi-wasteful, since we do not need to know the exact number of bits set, only whether or not there is at least one of them. Implement a new helper function to check just that. Suggested-by: Patrick Steinhardt <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dab6093 commit e5d48bf

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ewah/bitmap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ size_t bitmap_popcount(struct bitmap *self)
169169
return count;
170170
}
171171

172+
int bitmap_is_empty(struct bitmap *self)
173+
{
174+
size_t i;
175+
for (i = 0; i < self->word_alloc; i++)
176+
if (self->words[i])
177+
return 0;
178+
return 1;
179+
}
180+
172181
int bitmap_equals(struct bitmap *self, struct bitmap *other)
173182
{
174183
struct bitmap *big, *small;

ewah/ewok.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,6 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other);
189189
void bitmap_or(struct bitmap *self, const struct bitmap *other);
190190

191191
size_t bitmap_popcount(struct bitmap *self);
192+
int bitmap_is_empty(struct bitmap *self);
192193

193194
#endif

0 commit comments

Comments
 (0)