Skip to content

Commit

Permalink
fix issue 666 (#667)
Browse files Browse the repository at this point in the history
* fix issue 666

* lint
  • Loading branch information
lemire authored Sep 30, 2024
1 parent 5f15802 commit 26ca918
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion benchmarks/containsmulti_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "benchmark.h"
#include "numbersfromtextfiles.h"
#include "portability.h"
#include "random.h"

void contains_multi_via_contains(roaring_bitmap_t* bm, const uint32_t* values,
Expand Down
5 changes: 4 additions & 1 deletion include/roaring/bitset/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ inline bool bitset_get(const bitset_t *bitset, size_t i) {
/* Count number of bits set. */
size_t bitset_count(const bitset_t *bitset);

/* Find the index of the first bit set. Or zero if the bitset is empty. */
/* Returns true if no bit is set. */
bool bitset_empty(const bitset_t *bitset);

/* Find the index of the first bit set. Or SIZE_MAX if the bitset is empty. */
size_t bitset_minimum(const bitset_t *bitset);

/* Find the index of the last bit set. Or zero if the bitset is empty. */
Expand Down
11 changes: 10 additions & 1 deletion src/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,23 @@ bool bitset_inplace_union(bitset_t *CROARING_CBITSET_RESTRICT b1,
return true;
}

bool bitset_empty(const bitset_t *bitset) {
for (size_t k = 0; k < bitset->arraysize; k++) {
if (bitset->array[k] != 0) {
return false;
}
}
return true;
}

size_t bitset_minimum(const bitset_t *bitset) {
for (size_t k = 0; k < bitset->arraysize; k++) {
uint64_t w = bitset->array[k];
if (w != 0) {
return roaring_trailing_zeroes(w) + k * 64;
}
}
return 0;
return SIZE_MAX;
}

bool bitset_grow(bitset_t *bitset, size_t newarraysize) {
Expand Down
1 change: 1 addition & 0 deletions tests/cbitset_unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void test_construct() {

void test_max_min() {
bitset_t *b = bitset_create();
assert_true(bitset_empty(b));
for (size_t k = 100; k < 1000; ++k) {
bitset_set(b, 3 * k);
assert_true(bitset_minimum(b) == 3 * 100);
Expand Down

0 comments on commit 26ca918

Please sign in to comment.