ewah: add bitmap_dup() function
There's no easy way to make a copy of a bitmap. Obviously a caller can iterate over the bits and set them one by one in a new bitmap, but we can go much faster by copying whole words with memcpy(). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Dec 8, 2020 at 17:03 UTC
ccae08e822d71aaae1aa2660631d7ded8f4b97e7
2 files changed
+8
ewah/bitmap.c
+7
@@ -35,6 +35,13 @@ struct bitmap *bitmap_new(void)
35
return bitmap_word_alloc(32);
36
}
37
38
+struct bitmap *bitmap_dup(const struct bitmap *src)
39
+{
40
+ struct bitmap *dst = bitmap_word_alloc(src->word_alloc);
41
+ COPY_ARRAY(dst->words, src->words, src->word_alloc);
42
+ return dst;
43
+}
44
+
45
static void bitmap_grow(struct bitmap *self, size_t word_alloc)
46
{
47
size_t old_size = self->word_alloc;
ewah/ewok.h
+1
@@ -173,6 +173,7 @@ struct bitmap {
173
174
struct bitmap *bitmap_new(void);
175
struct bitmap *bitmap_word_alloc(size_t word_alloc);
176
+struct bitmap *bitmap_dup(const struct bitmap *src);
177
void bitmap_set(struct bitmap *self, size_t pos);
178
void bitmap_unset(struct bitmap *self, size_t pos);
179
int bitmap_get(struct bitmap *self, size_t pos);