Skip to content

Commit 0481cbf

Browse files
ttaylorrgitster
authored andcommitted
ewah: implement ewah_bitmap_popcount()
Some of the pseudo-merge test helpers (which will be introduced in the following commit) will want to indicate the total number of commits in or objects reachable from a pseudo-merge. Implement a popcount() function that operates on EWAH bitmaps to quickly determine how many bits are set in each of the respective bitmaps. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 955747b commit 0481cbf

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

ewah/bitmap.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ size_t bitmap_popcount(struct bitmap *self)
212212
return count;
213213
}
214214

215+
size_t ewah_bitmap_popcount(struct ewah_bitmap *self)
216+
{
217+
struct ewah_iterator it;
218+
eword_t word;
219+
size_t count = 0;
220+
221+
ewah_iterator_init(&it, self);
222+
223+
while (ewah_iterator_next(&word, &it))
224+
count += ewah_bit_popcount64(word);
225+
226+
return count;
227+
}
228+
215229
int bitmap_is_empty(struct bitmap *self)
216230
{
217231
size_t i;

ewah/ewok.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other);
195195
void bitmap_or(struct bitmap *self, const struct bitmap *other);
196196

197197
size_t bitmap_popcount(struct bitmap *self);
198+
size_t ewah_bitmap_popcount(struct ewah_bitmap *self);
198199
int bitmap_is_empty(struct bitmap *self);
199200

200201
#endif

0 commit comments

Comments
 (0)