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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
May 23, 2024 at 17:27 UTC
0481cbf912e23d96076e3a7e149e76a0327a7a70
2 files changed
+15
ewah/bitmap.c
+14
@@ -212,6 +212,20 @@ size_t bitmap_popcount(struct bitmap *self)
212
return count;
213
}
214
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
+
229
int bitmap_is_empty(struct bitmap *self)
230
{
231
size_t i;
ewah/ewok.h
+1
@@ -195,6 +195,7 @@ void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other);
195
void bitmap_or(struct bitmap *self, const struct bitmap *other);
196
197
size_t bitmap_popcount(struct bitmap *self);
198
+size_t ewah_bitmap_popcount(struct ewah_bitmap *self);
199
int bitmap_is_empty(struct bitmap *self);
200
201
#endif