aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2024-04-29 16:44:03 -0400
committerJunio C Hamano <gitster@pobox.com>2024-04-30 13:00:27 -0700
commit7c118146ec62d96bd1a2d24978720c08823dfe36 (patch)
tree0d176da236355f7b2add88f4395aceeb19545cba
parentf84071f6db32a34de5dcd35fee0e7f3fd8f4765f (diff)
downloadgit-7c118146ec62d96bd1a2d24978720c08823dfe36.tar.gz
ewah: implement `ewah_bitmap_popcount()`
Notice: this object is not reachable from any branch.
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>
Notice: this object is not reachable from any branch.
-rw-r--r--ewah/bitmap.c14
-rw-r--r--ewah/ewok.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/ewah/bitmap.c b/ewah/bitmap.c
index d352fec54c..dc2ca190f1 100644
--- a/ewah/bitmap.c
+++ b/ewah/bitmap.c
@@ -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;
diff --git a/ewah/ewok.h b/ewah/ewok.h
index 2b6c4ac499..7074a6347b 100644
--- a/ewah/ewok.h
+++ b/ewah/ewok.h
@@ -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