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 <ps@pks.im>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Taylor Blau 2023-12-14 17:23:59 -05:00 committed by Junio C Hamano
parent dab60934e3
commit e5d48bf38b
2 changed files with 10 additions and 0 deletions

View File

@ -169,6 +169,15 @@ size_t bitmap_popcount(struct bitmap *self)
return count;
}
int bitmap_is_empty(struct bitmap *self)
{
size_t i;
for (i = 0; i < self->word_alloc; i++)
if (self->words[i])
return 0;
return 1;
}
int bitmap_equals(struct bitmap *self, struct bitmap *other)
{
struct bitmap *big, *small;

View File

@ -189,5 +189,6 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other);
void bitmap_or(struct bitmap *self, const struct bitmap *other);
size_t bitmap_popcount(struct bitmap *self);
int bitmap_is_empty(struct bitmap *self);
#endif