bitmap: implement bitmap_is_subset()
The bitmap_is_subset() function checks if the 'self' bitmap contains any bitmaps that are not on in the 'other' bitmap. Up until this patch, it had a declaration, but no implementation or callers. A subsequent patch will want this function, so implement it here. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Dec 8, 2020 at 17:04 UTC
ed03a58b655f661ef6f9efd8816efe0c8cf07fa0
2 files changed
+22
-1
ewah/bitmap.c
+21
@@ -195,6 +195,27 @@ int bitmap_equals(struct bitmap *self, struct bitmap *other)
195
return 1;
196
}
197
198
+int bitmap_is_subset(struct bitmap *self, struct bitmap *other)
199
+{
200
+ size_t common_size, i;
201
+
202
+ if (self->word_alloc < other->word_alloc)
203
+ common_size = self->word_alloc;
204
+ else {
205
+ common_size = other->word_alloc;
206
+ for (i = common_size; i < self->word_alloc; i++) {
207
+ if (self->words[i])
208
+ return 1;
209
+ }
210
+ }
211
+
212
+ for (i = 0; i < common_size; i++) {
213
+ if (self->words[i] & ~other->words[i])
214
+ return 1;
215
+ }
216
+ return 0;
217
+}
218
+
219
void bitmap_reset(struct bitmap *bitmap)
220
{
221
memset(bitmap->words, 0x0, bitmap->word_alloc * sizeof(eword_t));
ewah/ewok.h
+1
-1
@@ -180,7 +180,7 @@ int bitmap_get(struct bitmap *self, size_t pos);
180
void bitmap_reset(struct bitmap *self);
181
void bitmap_free(struct bitmap *self);
182
int bitmap_equals(struct bitmap *self, struct bitmap *other);
183
-int bitmap_is_subset(struct bitmap *self, struct bitmap *super);
183
+int bitmap_is_subset(struct bitmap *self, struct bitmap *other);
184
185
struct ewah_bitmap * bitmap_to_ewah(struct bitmap *bitmap);
186
struct bitmap *ewah_to_bitmap(struct ewah_bitmap *ewah);