Skip to content

Commit 26ca918

Browse files
authored
fix issue 666 (#667)
* fix issue 666 * lint
1 parent 5f15802 commit 26ca918

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

benchmarks/containsmulti_benchmark.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "benchmark.h"
1010
#include "numbersfromtextfiles.h"
11-
#include "portability.h"
1211
#include "random.h"
1312

1413
void contains_multi_via_contains(roaring_bitmap_t* bm, const uint32_t* values,

include/roaring/bitset/bitset.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ inline bool bitset_get(const bitset_t *bitset, size_t i) {
131131
/* Count number of bits set. */
132132
size_t bitset_count(const bitset_t *bitset);
133133

134-
/* Find the index of the first bit set. Or zero if the bitset is empty. */
134+
/* Returns true if no bit is set. */
135+
bool bitset_empty(const bitset_t *bitset);
136+
137+
/* Find the index of the first bit set. Or SIZE_MAX if the bitset is empty. */
135138
size_t bitset_minimum(const bitset_t *bitset);
136139

137140
/* Find the index of the last bit set. Or zero if the bitset is empty. */

src/bitset.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,23 @@ bool bitset_inplace_union(bitset_t *CROARING_CBITSET_RESTRICT b1,
216216
return true;
217217
}
218218

219+
bool bitset_empty(const bitset_t *bitset) {
220+
for (size_t k = 0; k < bitset->arraysize; k++) {
221+
if (bitset->array[k] != 0) {
222+
return false;
223+
}
224+
}
225+
return true;
226+
}
227+
219228
size_t bitset_minimum(const bitset_t *bitset) {
220229
for (size_t k = 0; k < bitset->arraysize; k++) {
221230
uint64_t w = bitset->array[k];
222231
if (w != 0) {
223232
return roaring_trailing_zeroes(w) + k * 64;
224233
}
225234
}
226-
return 0;
235+
return SIZE_MAX;
227236
}
228237

229238
bool bitset_grow(bitset_t *bitset, size_t newarraysize) {

tests/cbitset_unit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void test_construct() {
6060

6161
void test_max_min() {
6262
bitset_t *b = bitset_create();
63+
assert_true(bitset_empty(b));
6364
for (size_t k = 100; k < 1000; ++k) {
6465
bitset_set(b, 3 * k);
6566
assert_true(bitset_minimum(b) == 3 * 100);

0 commit comments

Comments
 (0)