]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ewah: implement `ewah_bitmap_popcount()`
authorTaylor Blau <me@ttaylorr.com>
Thu, 23 May 2024 21:27:02 +0000 (17:27 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 May 2024 18:40:43 +0000 (11:40 -0700)
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>
ewah/bitmap.c
ewah/ewok.h

index d352fec54cef70cafa21959b3e804a1ea254d21f..dc2ca190f127d2d3d0c2f66375ad7df6399f2c3e 100644 (file)
@@ -212,6 +212,20 @@ size_t bitmap_popcount(struct bitmap *self)
        return count;
 }
 
+size_t ewah_bitmap_popcount(struct ewah_bitmap *self)
+{
+       struct ewah_iterator it;
+       eword_t word;
+       size_t count = 0;
+
+       ewah_iterator_init(&it, self);
+
+       while (ewah_iterator_next(&word, &it))
+               count += ewah_bit_popcount64(word);
+
+       return count;
+}
+
 int bitmap_is_empty(struct bitmap *self)
 {
        size_t i;
index 2b6c4ac499c7dafe87a433d26454eb5963752450..7074a6347b73f248ff6254e2bd0faeed253d48b5 100644 (file)
@@ -195,6 +195,7 @@ 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);
+size_t ewah_bitmap_popcount(struct ewah_bitmap *self);
 int bitmap_is_empty(struct bitmap *self);
 
 #endif