From 04584a49656ea770c77e3eee9537e1b726118cb6 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 30 Aug 2004 04:49:44 +0000 Subject: [PATCH] Make user responsible for allocating `struct bitmap's. --- src/lib/bitmap.c | 27 ++++++++++----------------- src/lib/bitmap.h | 8 +++++++- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c index 84a6ae4..616056f 100644 --- a/src/lib/bitmap.c +++ b/src/lib/bitmap.c @@ -10,12 +10,6 @@ typedef unsigned long elem_type; #define ELEM_IDX(BIT_IDX) ((BIT_IDX) / ELEM_BITS) #define BIT_MASK(BIT_IDX) ((elem_type) 1 << ((BIT_IDX) % ELEM_BITS)) -struct bitmap - { - size_t bit_cnt; - elem_type *bits; - }; - static inline size_t elem_cnt (const struct bitmap *b) { @@ -28,31 +22,30 @@ byte_cnt (const struct bitmap *b) return sizeof (elem_type) * elem_cnt (b); } -struct bitmap * -bitmap_create (size_t bit_cnt) +void +bitmap_init (struct bitmap *b, size_t bit_cnt) { - struct bitmap *b = malloc (sizeof *b); - if (b == NULL) - return NULL; - b->bit_cnt = bit_cnt; b->bits = malloc (byte_cnt (b)); if (b->bits == NULL && bit_cnt > 0) - { - free (b); - return NULL; - } + return NULL; + bitmap_set_all (b, false); return b; } +size_t +bitmap_storage_size (const struct bitmap *b) +{ + return byte_cnt (b); +} + void bitmap_destroy (struct bitmap *b) { ASSERT (b); free (b->bits); - free (b); } size_t diff --git a/src/lib/bitmap.h b/src/lib/bitmap.h index 50d8db6..ba4465e 100644 --- a/src/lib/bitmap.h +++ b/src/lib/bitmap.h @@ -4,7 +4,13 @@ #include #include -struct bitmap *bitmap_create (size_t bit_cnt); +struct bitmap + { + size_t bit_cnt; + elem_type *bits; + }; + +void bitmap_init (struct bitmap *, size_t bit_cnt); void bitmap_destroy (struct bitmap *); size_t bitmap_size (const struct bitmap *); -- 2.30.2