diff --git a/src/bitset.c b/src/bitset.c index 3472b9c..1366dd8 100644 --- a/src/bitset.c +++ b/src/bitset.c @@ -24,18 +24,18 @@ #define BITMAP_ASSERT(EXPR, OP) ((void) (EXPR)) #else -static inline void mir_bitmap_assert_fail (const char *op) { - fprintf (stderr, "wrong %s for a bitmap", op); +static inline void mir_bitset_assert_fail (const char *op) { + fprintf (stderr, "wrong %s for a bitset", op); assert (0); } -#define BITMAP_ASSERT(EXPR, OP) (void) ((EXPR) ? 0 : (mir_bitmap_assert_fail (#OP), 0)) +#define BITMAP_ASSERT(EXPR, OP) (void) ((EXPR) ? 0 : (mir_bitset_assert_fail (#OP), 0)) #endif #define BITMAP_WORD_BITS 64 -struct bitset_t * raviX_bitmap_create2(size_t init_bits_num) { +struct bitset_t * raviX_bitset_create2(size_t init_bits_num) { struct bitset_t * bm = calloc(1, sizeof(struct bitset_t)); bm->els_num = 0; bm->size = (init_bits_num + BITMAP_WORD_BITS - 1) / BITMAP_WORD_BITS; @@ -43,13 +43,13 @@ struct bitset_t * raviX_bitmap_create2(size_t init_bits_num) { return bm; } -void raviX_bitmap_destroy(struct bitset_t * bm) +void raviX_bitset_destroy(struct bitset_t * bm) { free(bm->varr); free(bm); } -static void bitmap_expand (struct bitset_t * bm, size_t nb) { +static void bitset_expand (struct bitset_t * bm, size_t nb) { size_t new_len = (nb + BITMAP_WORD_BITS - 1) / BITMAP_WORD_BITS; if (new_len > bm->els_num) { if (new_len > bm->size) { @@ -60,7 +60,7 @@ static void bitmap_expand (struct bitset_t * bm, size_t nb) { } } -int raviX_bitmap_bit_p(const struct bitset_t * bm, size_t nb) { +int raviX_bitset_bit_p(const struct bitset_t * bm, size_t nb) { size_t nw, sh, len = bm->els_num; bitset_el_t *addr = bm->varr; @@ -70,12 +70,12 @@ int raviX_bitmap_bit_p(const struct bitset_t * bm, size_t nb) { return (addr[nw] >> sh) & 1; } -int raviX_bitmap_set_bit_p(struct bitset_t * bm, size_t nb) { +int raviX_bitset_set_bit_p(struct bitset_t * bm, size_t nb) { size_t nw, sh; bitset_el_t *addr; int res; - bitmap_expand (bm, nb + 1); + bitset_expand (bm, nb + 1); addr = bm->varr; nw = nb / BITMAP_WORD_BITS; sh = nb % BITMAP_WORD_BITS; @@ -85,7 +85,7 @@ int raviX_bitmap_set_bit_p(struct bitset_t * bm, size_t nb) { return res; } -int raviX_bitmap_clear_bit_p(struct bitset_t * bm, size_t nb) { +int raviX_bitset_clear_bit_p(struct bitset_t * bm, size_t nb) { size_t nw, sh, len = bm->els_num; bitset_el_t *addr = bm->varr; int res; @@ -98,12 +98,12 @@ int raviX_bitmap_clear_bit_p(struct bitset_t * bm, size_t nb) { return res; } -int raviX_bitmap_set_or_clear_bit_range_p(struct bitset_t * bm, size_t nb, size_t len, int set_p) { +int raviX_bitset_set_or_clear_bit_range_p(struct bitset_t * bm, size_t nb, size_t len, int set_p) { size_t nw, lsh, rsh, range_len; bitset_el_t mask, *addr; int res = 0; - bitmap_expand (bm, nb + len); + bitset_expand (bm, nb + len); addr = bm->varr; while (len > 0) { nw = nb / BITMAP_WORD_BITS; @@ -124,7 +124,7 @@ int raviX_bitmap_set_or_clear_bit_range_p(struct bitset_t * bm, size_t nb, size_ return res; } -void raviX_bitmap_copy(struct bitset_t * dst, const struct bitset_t * src) { +void raviX_bitset_copy(struct bitset_t * dst, const struct bitset_t * src) { size_t dst_len = dst->els_num; size_t src_len = src->els_num; @@ -132,12 +132,12 @@ void raviX_bitmap_copy(struct bitset_t * dst, const struct bitset_t * src) { if (dst_len >= src_len) dst->els_num = src_len; else - bitmap_expand (dst, src_len * BITMAP_WORD_BITS); + bitset_expand (dst, src_len * BITMAP_WORD_BITS); memcpy (dst->varr, src->varr, src_len * sizeof (bitset_el_t)); } -int raviX_bitmap_equal_p(const struct bitset_t * bm1, const struct bitset_t * bm2) { +int raviX_bitset_equal_p(const struct bitset_t * bm1, const struct bitset_t * bm2) { const struct bitset_t * temp_bm; size_t i, temp_len, bm1_len = bm1->els_num; size_t bm2_len = bm2->els_num; @@ -159,7 +159,7 @@ int raviX_bitmap_equal_p(const struct bitset_t * bm1, const struct bitset_t * bm return true; } -int raviX_bitmap_intersect_p(const struct bitset_t * bm1, const struct bitset_t * bm2) { +int raviX_bitset_intersect_p(const struct bitset_t * bm1, const struct bitset_t * bm2) { size_t i, min_len, bm1_len = bm1->els_num; size_t bm2_len = bm2->els_num; bitset_el_t *addr1 = bm1->varr; @@ -171,7 +171,7 @@ int raviX_bitmap_intersect_p(const struct bitset_t * bm1, const struct bitset_t return false; } -int raviX_bitmap_empty_p(const struct bitset_t * bm) { +int raviX_bitset_empty_p(const struct bitset_t * bm) { size_t i, len = bm->els_num; bitset_el_t *addr = bm->varr; @@ -180,17 +180,17 @@ int raviX_bitmap_empty_p(const struct bitset_t * bm) { return true; } -static bitset_el_t bitmap_el_max2 (bitset_el_t el1, bitset_el_t el2) { +static bitset_el_t bitset_el_max2 (bitset_el_t el1, bitset_el_t el2) { return el1 < el2 ? el2 : el1; } -static bitset_el_t bitmap_el_max3 (bitset_el_t el1, bitset_el_t el2, bitset_el_t el3) { +static bitset_el_t bitset_el_max3 (bitset_el_t el1, bitset_el_t el2, bitset_el_t el3) { if (el1 <= el2) return el2 < el3 ? el3 : el2; return el1 < el3 ? el3 : el1; } /* Return the number of bits set in BM. */ -size_t raviX_bitmap_bit_count(const struct bitset_t * bm) { +size_t raviX_bitset_bit_count(const struct bitset_t * bm) { size_t i, len = bm->els_num; bitset_el_t el, *addr = bm->varr; size_t count = 0; @@ -204,7 +204,7 @@ size_t raviX_bitmap_bit_count(const struct bitset_t * bm) { return count; } -int raviX_bitmap_op2(struct bitset_t * dst, const struct bitset_t * src1, const struct bitset_t * src2, +int raviX_bitset_op2(struct bitset_t * dst, const struct bitset_t * src1, const struct bitset_t * src2, bitset_el_t (*op) (bitset_el_t, bitset_el_t)) { size_t i, len, bound, src1_len, src2_len; bitset_el_t old, *dst_addr, *src1_addr, *src2_addr; @@ -212,8 +212,8 @@ int raviX_bitmap_op2(struct bitset_t * dst, const struct bitset_t * src1, const src1_len = src1->els_num; src2_len = src2->els_num; - len = bitmap_el_max2 (src1_len, src2_len); - bitmap_expand (dst, len * BITMAP_WORD_BITS); + len = bitset_el_max2 (src1_len, src2_len); + bitset_expand (dst, len * BITMAP_WORD_BITS); dst_addr = dst->varr; src1_addr = src1->varr; src2_addr = src2->varr; @@ -228,7 +228,7 @@ int raviX_bitmap_op2(struct bitset_t * dst, const struct bitset_t * src1, const return change_p; } -int raviX_bitmap_op3(struct bitset_t * dst, const struct bitset_t * src1, const struct bitset_t * src2, +int raviX_bitset_op3(struct bitset_t * dst, const struct bitset_t * src1, const struct bitset_t * src2, const struct bitset_t * src3, bitset_el_t (*op) (bitset_el_t, bitset_el_t, bitset_el_t)) { size_t i, len, bound, src1_len, src2_len, src3_len; bitset_el_t old, *dst_addr, *src1_addr, *src2_addr, *src3_addr; @@ -237,8 +237,8 @@ int raviX_bitmap_op3(struct bitset_t * dst, const struct bitset_t * src1, const src1_len = src1->els_num; src2_len = src2->els_num; src3_len = src3->els_num; - len = bitmap_el_max3 (src1_len, src2_len, src3_len); - bitmap_expand (dst, len * BITMAP_WORD_BITS); + len = bitset_el_max3 (src1_len, src2_len, src3_len); + bitset_expand (dst, len * BITMAP_WORD_BITS); dst_addr = dst->varr; src1_addr = src1->varr; src2_addr = src2->varr; @@ -255,10 +255,10 @@ int raviX_bitmap_op3(struct bitset_t * dst, const struct bitset_t * src1, const return change_p; } -int raviX_bitmap_iterator_next(bitmap_iterator_t *iter, size_t *nbit) { +int raviX_bitset_iterator_next(bitset_iterator_t *iter, size_t *nbit) { const size_t el_bits_num = sizeof (bitset_el_t) * CHAR_BIT; - size_t curr_nel = iter->nbit / el_bits_num, len = iter->bitmap->els_num; - bitset_el_t el, *addr = iter->bitmap->varr; + size_t curr_nel = iter->nbit / el_bits_num, len = iter->bitset->els_num; + bitset_el_t el, *addr = iter->bitset->varr; for (; curr_nel < len; curr_nel++, iter->nbit = curr_nel * el_bits_num) if ((el = addr[curr_nel]) != 0) diff --git a/src/bitset.h b/src/bitset.h index 24f3257..1572238 100644 --- a/src/bitset.h +++ b/src/bitset.h @@ -1,3 +1,10 @@ +/* This file is a part of MIR project. + Copyright (C) 2018-2020 Vladimir Makarov . +*/ +/* + * Adapted for Ravi Compiler project + */ + #ifndef ravicomp_BITSET_H #define ravicomp_BITSET_H @@ -13,76 +20,76 @@ struct bitset_t { bitset_el_t *varr; }; -extern struct bitset_t * raviX_bitmap_create2(size_t init_bits_num); -static inline struct bitset_t * raviX_bitmap_create(void) +extern struct bitset_t * raviX_bitset_create2(size_t init_bits_num); +static inline struct bitset_t * raviX_bitset_create(void) { - return raviX_bitmap_create2(0); + return raviX_bitset_create2(0); } -extern void raviX_bitmap_destroy(struct bitset_t * bm); -static inline void raviX_bitmap_clear(struct bitset_t * bm) +extern void raviX_bitset_destroy(struct bitset_t * bm); +static inline void raviX_bitset_clear(struct bitset_t * bm) { bm->els_num = 0; } -extern int raviX_bitmap_bit_p(const struct bitset_t * bm, size_t nb); -extern int raviX_bitmap_set_bit_p(struct bitset_t * bm, size_t nb); -extern int raviX_bitmap_clear_bit_p(struct bitset_t * bm, size_t nb); -extern int raviX_bitmap_set_or_clear_bit_range_p(struct bitset_t * bm, size_t nb, size_t len, int set_p); -static inline int raviX_bitmap_set_bit_range_p(struct bitset_t * bm, size_t nb, size_t len) { - return raviX_bitmap_set_or_clear_bit_range_p(bm, nb, len, true); +extern int raviX_bitset_bit_p(const struct bitset_t * bm, size_t nb); +extern int raviX_bitset_set_bit_p(struct bitset_t * bm, size_t nb); +extern int raviX_bitset_clear_bit_p(struct bitset_t * bm, size_t nb); +extern int raviX_bitset_set_or_clear_bit_range_p(struct bitset_t * bm, size_t nb, size_t len, int set_p); +static inline int raviX_bitset_set_bit_range_p(struct bitset_t * bm, size_t nb, size_t len) { + return raviX_bitset_set_or_clear_bit_range_p(bm, nb, len, true); } -static inline int raviX_bitmap_clear_bit_range_p(struct bitset_t * bm, size_t nb, size_t len) { - return raviX_bitmap_set_or_clear_bit_range_p(bm, nb, len, false); +static inline int raviX_bitset_clear_bit_range_p(struct bitset_t * bm, size_t nb, size_t len) { + return raviX_bitset_set_or_clear_bit_range_p(bm, nb, len, false); } -extern void raviX_bitmap_copy(struct bitset_t * dst, const struct bitset_t * src); -extern int raviX_bitmap_equal_p(const struct bitset_t * bm1, const struct bitset_t * bm2); -extern int raviX_bitmap_intersect_p(const struct bitset_t * bm1, const struct bitset_t * bm2); -extern int raviX_bitmap_empty_p(const struct bitset_t * bm); +extern void raviX_bitset_copy(struct bitset_t * dst, const struct bitset_t * src); +extern int raviX_bitset_equal_p(const struct bitset_t * bm1, const struct bitset_t * bm2); +extern int raviX_bitset_intersect_p(const struct bitset_t * bm1, const struct bitset_t * bm2); +extern int raviX_bitset_empty_p(const struct bitset_t * bm); /* Return the number of bits set in BM. */ -extern size_t raviX_bitmap_bit_count(const struct bitset_t * bm); -extern int raviX_bitmap_op2(struct bitset_t * dst, const struct bitset_t * src1, const struct bitset_t * src2, +extern size_t raviX_bitset_bit_count(const struct bitset_t * bm); +extern int raviX_bitset_op2(struct bitset_t * dst, const struct bitset_t * src1, const struct bitset_t * src2, bitset_el_t (*op) (bitset_el_t, bitset_el_t)); -static inline bitset_el_t raviX_bitmap_el_and(bitset_el_t el1, bitset_el_t el2) { return el1 & el2; } -static inline int raviX_bitmap_and(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2) { - return raviX_bitmap_op2(dst, src1, src2, raviX_bitmap_el_and); +static inline bitset_el_t raviX_bitset_el_and(bitset_el_t el1, bitset_el_t el2) { return el1 & el2; } +static inline int raviX_bitset_and(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2) { + return raviX_bitset_op2(dst, src1, src2, raviX_bitset_el_and); } -static inline bitset_el_t raviX_bitmap_el_and_compl(bitset_el_t el1, bitset_el_t el2) { +static inline bitset_el_t raviX_bitset_el_and_compl(bitset_el_t el1, bitset_el_t el2) { return el1 & ~el2; } -static inline int raviX_bitmap_and_compl(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2) { - return raviX_bitmap_op2(dst, src1, src2, raviX_bitmap_el_and_compl); +static inline int raviX_bitset_and_compl(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2) { + return raviX_bitset_op2(dst, src1, src2, raviX_bitset_el_and_compl); } -static inline bitset_el_t raviX_bitmap_el_ior(bitset_el_t el1, bitset_el_t el2) { return el1 | el2; } -static inline int raviX_bitmap_ior(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2) { - return raviX_bitmap_op2(dst, src1, src2, raviX_bitmap_el_ior); +static inline bitset_el_t raviX_bitset_el_ior(bitset_el_t el1, bitset_el_t el2) { return el1 | el2; } +static inline int raviX_bitset_ior(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2) { + return raviX_bitset_op2(dst, src1, src2, raviX_bitset_el_ior); } -int raviX_bitmap_op3(struct bitset_t * dst, const struct bitset_t * src1, const struct bitset_t * src2, +int raviX_bitset_op3(struct bitset_t * dst, const struct bitset_t * src1, const struct bitset_t * src2, const struct bitset_t * src3, bitset_el_t (*op) (bitset_el_t, bitset_el_t, bitset_el_t)); -static inline bitset_el_t raviX_bitmap_el_ior_and(bitset_el_t el1, bitset_el_t el2, bitset_el_t el3) { +static inline bitset_el_t raviX_bitset_el_ior_and(bitset_el_t el1, bitset_el_t el2, bitset_el_t el3) { return el1 | (el2 & el3); } /* DST = SRC1 | (SRC2 & SRC3). Return true if DST changed. */ -static inline int raviX_bitmap_ior_and(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2, struct bitset_t * src3) { - return raviX_bitmap_op3(dst, src1, src2, src3, raviX_bitmap_el_ior_and); +static inline int raviX_bitset_ior_and(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2, struct bitset_t * src3) { + return raviX_bitset_op3(dst, src1, src2, src3, raviX_bitset_el_ior_and); } -static inline bitset_el_t raviX_bitmap_el_ior_and_compl(bitset_el_t el1, bitset_el_t el2, bitset_el_t el3) { +static inline bitset_el_t raviX_bitset_el_ior_and_compl(bitset_el_t el1, bitset_el_t el2, bitset_el_t el3) { return el1 | (el2 & ~el3); } /* DST = SRC1 | (SRC2 & ~SRC3). Return true if DST changed. */ -static inline int raviX_bitmap_ior_and_compl(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2, struct bitset_t * src3) { - return raviX_bitmap_op3(dst, src1, src2, src3, raviX_bitmap_el_ior_and_compl); +static inline int raviX_bitset_ior_and_compl(struct bitset_t * dst, struct bitset_t * src1, struct bitset_t * src2, struct bitset_t * src3) { + return raviX_bitset_op3(dst, src1, src2, src3, raviX_bitset_el_ior_and_compl); } typedef struct { - struct bitset_t * bitmap; + struct bitset_t * bitset; size_t nbit; -} bitmap_iterator_t; -static inline void raviX_bitmap_iterator_init(bitmap_iterator_t *iter, struct bitset_t * bitmap) { - iter->bitmap = bitmap; +} bitset_iterator_t; +static inline void raviX_bitset_iterator_init(bitset_iterator_t *iter, struct bitset_t * bitset) { + iter->bitset = bitset; iter->nbit = 0; } -extern int raviX_bitmap_iterator_next(bitmap_iterator_t *iter, size_t *nbit); -#define FOREACH_BITMAP_BIT(iter, bitmap, nbit) \ - for (raviX_bitmap_iterator_init (&iter, bitmap); raviX_bitmap_iterator_next (&iter, &nbit);) +extern int raviX_bitset_iterator_next(bitset_iterator_t *iter, size_t *nbit); +#define FOREACH_BITSET_BIT(iter, bitset, nbit) \ + for (raviX_bitset_iterator_init (&iter, bitset); raviX_bitset_iterator_next (&iter, &nbit);) diff --git a/tests/tmisc.c b/tests/tmisc.c index 4b53dab..806ba7d 100644 --- a/tests/tmisc.c +++ b/tests/tmisc.c @@ -39,112 +39,112 @@ int test_memalloc() return 0; } -int test_bitmap() +int test_bitset() { int status; struct bitset_t * b1, *b2, *b3, *b4; - b1 = raviX_bitmap_create(); - b2 = raviX_bitmap_create(); - b3 = raviX_bitmap_create(); - b4 = raviX_bitmap_create(); - status = raviX_bitmap_empty_p(b1); - status &= raviX_bitmap_bit_count(b1) == 0; - - status &= raviX_bitmap_set_bit_p(b1, 1); - status &= raviX_bitmap_set_bit_p(b1, 120); - status &= !raviX_bitmap_set_bit_p(b1, 120); - status &= !raviX_bitmap_empty_p(b1); - status &= raviX_bitmap_bit_p(b1, 1); - status &= raviX_bitmap_bit_p(b1, 120); - status &= !raviX_bitmap_bit_p(b1, 42); - - status &= raviX_bitmap_clear_bit_p(b1, 120); - status &= !raviX_bitmap_bit_p(b1, 120); - status &= raviX_bitmap_set_bit_p(b1, 120); - - raviX_bitmap_copy(b2, b1); - status &= raviX_bitmap_equal_p(b1, b2); - status &= raviX_bitmap_intersect_p(b1, b2); - status &= !raviX_bitmap_equal_p(b1, b3); - status &= !raviX_bitmap_intersect_p(b1, b3); - - raviX_bitmap_clear(b2); - status &= raviX_bitmap_empty_p(b2); - status &= raviX_bitmap_bit_count(b2) == 0; - - raviX_bitmap_copy(b2, b1); - status &= raviX_bitmap_equal_p(b1, b2); - status &= raviX_bitmap_set_bit_p(b2, 1818); - - status &= raviX_bitmap_set_bit_p(b3, 555); - status &= raviX_bitmap_set_bit_p(b3, 120); - status &= raviX_bitmap_set_bit_p(b3, 42); - status &= !raviX_bitmap_empty_p(b3); - status &= raviX_bitmap_bit_count(b3) == 3; - status &= raviX_bitmap_bit_p(b3, 555); - status &= raviX_bitmap_bit_p(b3, 120); - status &= raviX_bitmap_bit_p(b3, 42); - - status &= raviX_bitmap_and(b4, b1, b2); - status &= raviX_bitmap_equal_p(b4, b1); - - status &= raviX_bitmap_ior(b4, b1, b2); - status &= raviX_bitmap_equal_p(b4, b2); - - status &= raviX_bitmap_and_compl(b4, b2, b1); - status &= raviX_bitmap_bit_p(b4, 1818); - status &= raviX_bitmap_bit_count(b4) == 1; - - status &= raviX_bitmap_and_compl(b4, b1, b2); - status &= raviX_bitmap_bit_count(b4) == 0; - - status &= raviX_bitmap_ior_and(b4, b1, b2, b3); - status &= raviX_bitmap_bit_p(b4, 1); - status &= raviX_bitmap_bit_p(b4, 120); - status &= raviX_bitmap_bit_count(b4) == 2; - - status &= raviX_bitmap_ior_and(b4, b3, b1, b2); - status &= raviX_bitmap_bit_p(b4, 1); - status &= raviX_bitmap_bit_p(b4, 555); - status &= raviX_bitmap_bit_p(b4, 42); - status &= raviX_bitmap_bit_p(b4, 120); - status &= raviX_bitmap_bit_count(b4) == 4; - - status &= raviX_bitmap_ior_and_compl(b4, b1, b2, b3); - status &= raviX_bitmap_bit_p(b4, 1); - status &= raviX_bitmap_bit_p(b4, 1818); - status &= raviX_bitmap_bit_p(b4, 120); - status &= raviX_bitmap_bit_count(b4) == 3; - - status &= raviX_bitmap_ior_and_compl(b3, b1, b2, b3); - status &= raviX_bitmap_bit_p(b3, 1); - status &= raviX_bitmap_bit_p(b3, 1818); - status &= raviX_bitmap_bit_p(b3, 120); - status &= raviX_bitmap_bit_count(b3) == 3; - - raviX_bitmap_clear(b1); - status &= raviX_bitmap_set_bit_range_p(b1, 1, 62); - for (int i = 1; i <= 62; i++) status &= raviX_bitmap_clear_bit_p(b1, i); - status &= raviX_bitmap_empty_p(b1); - - status &= raviX_bitmap_set_bit_range_p(b1, 30, 362); - for (int i = 30; i < 362 + 30; i++) status &= raviX_bitmap_clear_bit_p(b1, i); - status &= raviX_bitmap_empty_p(b1); - - status &= raviX_bitmap_set_bit_range_p(b1, 1, 62); - status &= raviX_bitmap_clear_bit_range_p(b1, 1, 62); - status &= raviX_bitmap_empty_p(b1); - - status &= raviX_bitmap_set_bit_range_p(b1, 30, 362); - status &= raviX_bitmap_clear_bit_range_p(b1, 30, 362); - status &= raviX_bitmap_empty_p(b1); - - status &= raviX_bitmap_set_bit_range_p(b1, 30, 362); - - bitmap_iterator_t iter; + b1 = raviX_bitset_create(); + b2 = raviX_bitset_create(); + b3 = raviX_bitset_create(); + b4 = raviX_bitset_create(); + status = raviX_bitset_empty_p(b1); + status &= raviX_bitset_bit_count(b1) == 0; + + status &= raviX_bitset_set_bit_p(b1, 1); + status &= raviX_bitset_set_bit_p(b1, 120); + status &= !raviX_bitset_set_bit_p(b1, 120); + status &= !raviX_bitset_empty_p(b1); + status &= raviX_bitset_bit_p(b1, 1); + status &= raviX_bitset_bit_p(b1, 120); + status &= !raviX_bitset_bit_p(b1, 42); + + status &= raviX_bitset_clear_bit_p(b1, 120); + status &= !raviX_bitset_bit_p(b1, 120); + status &= raviX_bitset_set_bit_p(b1, 120); + + raviX_bitset_copy(b2, b1); + status &= raviX_bitset_equal_p(b1, b2); + status &= raviX_bitset_intersect_p(b1, b2); + status &= !raviX_bitset_equal_p(b1, b3); + status &= !raviX_bitset_intersect_p(b1, b3); + + raviX_bitset_clear(b2); + status &= raviX_bitset_empty_p(b2); + status &= raviX_bitset_bit_count(b2) == 0; + + raviX_bitset_copy(b2, b1); + status &= raviX_bitset_equal_p(b1, b2); + status &= raviX_bitset_set_bit_p(b2, 1818); + + status &= raviX_bitset_set_bit_p(b3, 555); + status &= raviX_bitset_set_bit_p(b3, 120); + status &= raviX_bitset_set_bit_p(b3, 42); + status &= !raviX_bitset_empty_p(b3); + status &= raviX_bitset_bit_count(b3) == 3; + status &= raviX_bitset_bit_p(b3, 555); + status &= raviX_bitset_bit_p(b3, 120); + status &= raviX_bitset_bit_p(b3, 42); + + status &= raviX_bitset_and(b4, b1, b2); + status &= raviX_bitset_equal_p(b4, b1); + + status &= raviX_bitset_ior(b4, b1, b2); + status &= raviX_bitset_equal_p(b4, b2); + + status &= raviX_bitset_and_compl(b4, b2, b1); + status &= raviX_bitset_bit_p(b4, 1818); + status &= raviX_bitset_bit_count(b4) == 1; + + status &= raviX_bitset_and_compl(b4, b1, b2); + status &= raviX_bitset_bit_count(b4) == 0; + + status &= raviX_bitset_ior_and(b4, b1, b2, b3); + status &= raviX_bitset_bit_p(b4, 1); + status &= raviX_bitset_bit_p(b4, 120); + status &= raviX_bitset_bit_count(b4) == 2; + + status &= raviX_bitset_ior_and(b4, b3, b1, b2); + status &= raviX_bitset_bit_p(b4, 1); + status &= raviX_bitset_bit_p(b4, 555); + status &= raviX_bitset_bit_p(b4, 42); + status &= raviX_bitset_bit_p(b4, 120); + status &= raviX_bitset_bit_count(b4) == 4; + + status &= raviX_bitset_ior_and_compl(b4, b1, b2, b3); + status &= raviX_bitset_bit_p(b4, 1); + status &= raviX_bitset_bit_p(b4, 1818); + status &= raviX_bitset_bit_p(b4, 120); + status &= raviX_bitset_bit_count(b4) == 3; + + status &= raviX_bitset_ior_and_compl(b3, b1, b2, b3); + status &= raviX_bitset_bit_p(b3, 1); + status &= raviX_bitset_bit_p(b3, 1818); + status &= raviX_bitset_bit_p(b3, 120); + status &= raviX_bitset_bit_count(b3) == 3; + + raviX_bitset_clear(b1); + status &= raviX_bitset_set_bit_range_p(b1, 1, 62); + for (int i = 1; i <= 62; i++) status &= raviX_bitset_clear_bit_p(b1, i); + status &= raviX_bitset_empty_p(b1); + + status &= raviX_bitset_set_bit_range_p(b1, 30, 362); + for (int i = 30; i < 362 + 30; i++) status &= raviX_bitset_clear_bit_p(b1, i); + status &= raviX_bitset_empty_p(b1); + + status &= raviX_bitset_set_bit_range_p(b1, 1, 62); + status &= raviX_bitset_clear_bit_range_p(b1, 1, 62); + status &= raviX_bitset_empty_p(b1); + + status &= raviX_bitset_set_bit_range_p(b1, 30, 362); + status &= raviX_bitset_clear_bit_range_p(b1, 30, 362); + status &= raviX_bitset_empty_p(b1); + + status &= raviX_bitset_set_bit_range_p(b1, 30, 362); + + bitset_iterator_t iter; size_t nb = 0, n = 0, nmax = 0, nmin = 10000; - FOREACH_BITMAP_BIT(iter, b1, nb) + FOREACH_BITSET_BIT(iter, b1, nb) { n++; if (nmax < nb) nmax = nb; @@ -153,11 +153,11 @@ int test_bitmap() status &= n == 362; status &= nmin == 30 && nmax == 391; - fprintf (stderr, status ? "BITMAP OK\n" : "BITMAP FAILURE!\n"); - raviX_bitmap_destroy(b1); - raviX_bitmap_destroy(b2); - raviX_bitmap_destroy(b3); - raviX_bitmap_destroy(b4); + fprintf (stderr, status ? "BITSET OK\n" : "BITSET FAILURE!\n"); + raviX_bitset_destroy(b1); + raviX_bitset_destroy(b2); + raviX_bitset_destroy(b3); + raviX_bitset_destroy(b4); return !status; } @@ -165,7 +165,7 @@ int main(int argc, const char *argv[]) { int rc = test_stringset(); rc += test_memalloc(); - rc += test_bitmap(); + rc += test_bitset(); if (rc == 0) printf("Ok\n"); else