Skip to content

Commit ed03a58

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6dc5ef7 commit ed03a58

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ewah/bitmap.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ int bitmap_equals(struct bitmap *self, struct bitmap *other)
195195
return 1;
196196
}
197197

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+
198219
void bitmap_reset(struct bitmap *bitmap)
199220
{
200221
memset(bitmap->words, 0x0, bitmap->word_alloc * sizeof(eword_t));

ewah/ewok.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int bitmap_get(struct bitmap *self, size_t pos);
180180
void bitmap_reset(struct bitmap *self);
181181
void bitmap_free(struct bitmap *self);
182182
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);
184184

185185
struct ewah_bitmap * bitmap_to_ewah(struct bitmap *bitmap);
186186
struct bitmap *ewah_to_bitmap(struct ewah_bitmap *ewah);

0 commit comments

Comments
 (0)