diff --git a/README.md b/README.md index eb5ee927..0f938004 100644 --- a/README.md +++ b/README.md @@ -530,26 +530,26 @@ bitset_free(b); // frees memory More advanced example: ```C - bitset_t *b = bitset_create(); - for (int k = 0; k < 1000; ++k) { - bitset_set(b, 3 * k); - } - // We have bitset_count(b) == 1000. - // We have bitset_get(b, 3) is true - // You can iterate through the values: - size_t k = 0; - for (size_t i = 0; bitset_next_set_bit(b, &i); i++) { - // You will have i == k - k += 3; - } - // We support a wide range of operations on two bitsets such as - // bitset_inplace_symmetric_difference(b1,b2); - // bitset_inplace_symmetric_difference(b1,b2); - // bitset_inplace_difference(b1,b2);// should make no difference - // bitset_inplace_union(b1,b2); - // bitset_inplace_intersection(b1,b2); - // bitsets_disjoint - // bitsets_intersect +bitset_t *b = bitset_create(); +for (int k = 0; k < 1000; ++k) { + bitset_set(b, 3 * k); +} +// We have bitset_count(b) == 1000. +// We have bitset_get(b, 3) is true +// You can iterate through the values: +size_t k = 0; +for (size_t i = 0; bitset_next_set_bit(b, &i); i++) { + // You will have i == k + k += 3; +} +// We support a wide range of operations on two bitsets such as +// bitset_inplace_symmetric_difference(b1,b2); +// bitset_inplace_symmetric_difference(b1,b2); +// bitset_inplace_difference(b1,b2);// should make no difference +// bitset_inplace_union(b1,b2); +// bitset_inplace_intersection(b1,b2); +// bitsets_disjoint +// bitsets_intersect ``` In some instances, you may want to convert a Roaring bitmap into a conventional (uncompressed) bitset. @@ -557,28 +557,28 @@ Indeed, bitsets have advantages such as higher query performances in some cases. illustrates how you may do so: ```C - roaring_bitmap_t *r1 = roaring_bitmap_create(); - for (uint32_t i = 100; i < 100000; i+= 1 + (i%5)) { +roaring_bitmap_t *r1 = roaring_bitmap_create(); +for (uint32_t i = 100; i < 100000; i+= 1 + (i%5)) { roaring_bitmap_add(r1, i); - } - for (uint32_t i = 100000; i < 500000; i+= 100) { +} +for (uint32_t i = 100000; i < 500000; i+= 100) { roaring_bitmap_add(r1, i); - } - roaring_bitmap_add_range(r1, 500000, 600000); - bitset_t * bitset = bitset_create(); - bool success = roaring_bitmap_to_bitset(r1, bitset); - assert(success); // could fail due to memory allocation. - assert(bitset_count(bitset) == roaring_bitmap_get_cardinality(r1)); - // You can then query the bitset: - for (uint32_t i = 100; i < 100000; i+= 1 + (i%5)) { - assert(bitset_get(bitset,i)); - } - for (uint32_t i = 100000; i < 500000; i+= 100) { - assert(bitset_get(bitset,i)); - } - // you must free the memory: - bitset_free(bitset); - roaring_bitmap_free(r1); +} +roaring_bitmap_add_range(r1, 500000, 600000); +bitset_t * bitset = bitset_create(); +bool success = roaring_bitmap_to_bitset(r1, bitset); +assert(success); // could fail due to memory allocation. +assert(bitset_count(bitset) == roaring_bitmap_get_cardinality(r1)); +// You can then query the bitset: +for (uint32_t i = 100; i < 100000; i+= 1 + (i%5)) { + assert(bitset_get(bitset,i)); +} +for (uint32_t i = 100000; i < 500000; i+= 100) { + assert(bitset_get(bitset,i)); +} +// you must free the memory: +bitset_free(bitset); +roaring_bitmap_free(r1); ``` You should be aware that a convention bitset (`bitset_t *`) may use much more