ewah: `bitmap_equals_ewah()`
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>
Taylor Blau committed
May 23, 2024 at 17:27 UTC
94c1addf862619250a1584c05a43f80f1c8d7d72
2 files changed
+20
ewah/bitmap.c
+19
@@ -261,6 +261,25 @@ int bitmap_equals(struct bitmap *self, struct bitmap *other)
261
return 1;
262
}
263
264
+int bitmap_equals_ewah(struct bitmap *self, struct ewah_bitmap *other)
265
+{
266
+ struct ewah_iterator it;
267
+ eword_t word;
268
+ size_t i = 0;
269
+
270
+ ewah_iterator_init(&it, other);
271
+
272
+ while (ewah_iterator_next(&word, &it))
273
+ if (word != (i < self->word_alloc ? self->words[i++] : 0))
274
+ return 0;
275
+
276
+ for (; i < self->word_alloc; i++)
277
+ if (self->words[i])
278
+ return 0;
279
+
280
+ return 1;
281
+}
282
+
283
int bitmap_is_subset(struct bitmap *self, struct bitmap *other)
284
{
285
size_t common_size, i;
ewah/ewok.h
+1
@@ -179,6 +179,7 @@ void bitmap_unset(struct bitmap *self, size_t pos);
179
int bitmap_get(struct bitmap *self, size_t pos);
180
void bitmap_free(struct bitmap *self);
181
int bitmap_equals(struct bitmap *self, struct bitmap *other);
182
+int bitmap_equals_ewah(struct bitmap *self, struct ewah_bitmap *other);
183
184
/*
185
* Both `bitmap_is_subset()` and `ewah_bitmap_is_subset()` return 1 if the set