]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ewah: `bitmap_equals_ewah()`
authorTaylor Blau <me@ttaylorr.com>
Thu, 23 May 2024 21:27:18 +0000 (17:27 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 May 2024 18:40:44 +0000 (11:40 -0700)
Prepare to reuse existing pseudo-merge bitmaps by implementing a
`bitmap_equals_ewah()` helper.

This helper will be used to see if a raw bitmap (containing the set of
parents for some pseudo-merge) is equal to any existing pseudo-merge's
commits bitmap (which are stored as EWAH-compressed bitmaps on disk).

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ewah/bitmap.c
ewah/ewok.h

index dc2ca190f127d2d3d0c2f66375ad7df6399f2c3e..55928dada86a37f3dd291c775f7f109f908e74a4 100644 (file)
@@ -261,6 +261,25 @@ int bitmap_equals(struct bitmap *self, struct bitmap *other)
        return 1;
 }
 
+int bitmap_equals_ewah(struct bitmap *self, struct ewah_bitmap *other)
+{
+       struct ewah_iterator it;
+       eword_t word;
+       size_t i = 0;
+
+       ewah_iterator_init(&it, other);
+
+       while (ewah_iterator_next(&word, &it))
+               if (word != (i < self->word_alloc ? self->words[i++] : 0))
+                       return 0;
+
+       for (; i < self->word_alloc; i++)
+               if (self->words[i])
+                       return 0;
+
+       return 1;
+}
+
 int bitmap_is_subset(struct bitmap *self, struct bitmap *other)
 {
        size_t common_size, i;
index 7074a6347b73f248ff6254e2bd0faeed253d48b5..5e357e24933e977cc85331fd9dd17d506dd49139 100644 (file)
@@ -179,6 +179,7 @@ void bitmap_unset(struct bitmap *self, size_t pos);
 int bitmap_get(struct bitmap *self, size_t pos);
 void bitmap_free(struct bitmap *self);
 int bitmap_equals(struct bitmap *self, struct bitmap *other);
+int bitmap_equals_ewah(struct bitmap *self, struct ewah_bitmap *other);
 
 /*
  * Both `bitmap_is_subset()` and `ewah_bitmap_is_subset()` return 1 if the set