Skip to content

Commit

Permalink
fix: correct struct init + one array to array comp. (#627)
Browse files Browse the repository at this point in the history
* fix: correct struct init + one array to array comp.

* lint

* fix: complete init fixes in  toplevel_unit

---------

Co-authored-by: Daniel Lemire <dlemire@lemire.me>
  • Loading branch information
lemire and Daniel Lemire authored May 13, 2024
1 parent a4388f9 commit 44228a0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion benchmarks/add_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void run_test(uint32_t spanlen, uint32_t intvlen, double density,
for (int p = 0; p < num_passes; p++) {
roaring_bitmap_t *r = roaring_bitmap_create();
RDTSC_START(cycles_start);
roaring_bulk_context_t context = {0};
roaring_bulk_context_t context = {0, 0, 0, 0};
for (int64_t i = 0; i < count; i++) {
for (uint32_t j = 0; j < intvlen; j++) {
roaring_bitmap_add_bulk(r, &context, offsets[i] + j);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/containsmulti_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void contains_multi_via_contains(roaring_bitmap_t* bm, const uint32_t* values,

void contains_multi_bulk(roaring_bitmap_t* bm, const uint32_t* values,
bool* results, const size_t count) {
roaring_bulk_context_t context = {0};
roaring_bulk_context_t context = {0, 0};
for (size_t i = 0; i < count; ++i) {
results[i] = roaring_bitmap_contains_bulk(bm, &context, values[i]);
}
Expand Down
14 changes: 7 additions & 7 deletions src/art/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ static art_indexed_child_t art_node_next_child(const art_node_t *node,
return art_node256_next_child((art_node256_t *)node, index);
default:
assert(false);
return (art_indexed_child_t){0};
return (art_indexed_child_t){0, 0, 0};
}
}

Expand All @@ -1065,7 +1065,7 @@ static art_indexed_child_t art_node_prev_child(const art_node_t *node,
return art_node256_prev_child((art_node256_t *)node, index);
default:
assert(false);
return (art_indexed_child_t){0};
return (art_indexed_child_t){0, 0, 0};
}
}

Expand All @@ -1089,7 +1089,7 @@ static art_indexed_child_t art_node_child_at(const art_node_t *node,
return art_node256_child_at((art_node256_t *)node, index);
default:
assert(false);
return (art_indexed_child_t){0};
return (art_indexed_child_t){0, 0, 0};
}
}

Expand All @@ -1113,7 +1113,7 @@ static art_indexed_child_t art_node_lower_bound(const art_node_t *node,
return art_node256_lower_bound((art_node256_t *)node, key_chunk);
default:
assert(false);
return (art_indexed_child_t){0};
return (art_indexed_child_t){0, 0, 0};
}
}

Expand Down Expand Up @@ -1670,7 +1670,7 @@ static bool art_node_iterator_lower_bound(const art_node_t *node,
}

art_iterator_t art_init_iterator(const art_t *art, bool first) {
art_iterator_t iterator = {0};
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (art->root == NULL) {
return iterator;
}
Expand Down Expand Up @@ -1727,15 +1727,15 @@ bool art_iterator_lower_bound(art_iterator_t *iterator,
}

art_iterator_t art_lower_bound(const art_t *art, const art_key_chunk_t *key) {
art_iterator_t iterator = {0};
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (art->root != NULL) {
art_node_iterator_lower_bound(art->root, &iterator, key);
}
return iterator;
}

art_iterator_t art_upper_bound(const art_t *art, const art_key_chunk_t *key) {
art_iterator_t iterator = {0};
art_iterator_t iterator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (art->root != NULL) {
if (art_node_iterator_lower_bound(art->root, &iterator, key) &&
art_compare_keys(iterator.key, key) == 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/roaring.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ roaring_bitmap_t *roaring_bitmap_of(size_t n_args, ...) {
// todo: could be greatly optimized but we do not expect this call to ever
// include long lists
roaring_bitmap_t *answer = roaring_bitmap_create();
roaring_bulk_context_t context = {0};
roaring_bulk_context_t context = {0, 0, 0, 0};
va_list ap;
va_start(ap, n_args);
for (size_t i = 0; i < n_args; i++) {
Expand Down Expand Up @@ -1561,7 +1561,7 @@ roaring_bitmap_t *roaring_bitmap_deserialize(const void *buf) {
if (bitmap == NULL) {
return NULL;
}
roaring_bulk_context_t context = {0};
roaring_bulk_context_t context = {0, 0, 0, 0};
for (uint32_t i = 0; i < card; i++) {
// elems may not be aligned, read with memcpy
uint32_t elem;
Expand Down Expand Up @@ -1604,7 +1604,7 @@ roaring_bitmap_t *roaring_bitmap_deserialize_safe(const void *buf,
if (bitmap == NULL) {
return NULL;
}
roaring_bulk_context_t context = {0};
roaring_bulk_context_t context = {0, 0, 0, 0};
for (uint32_t i = 0; i < card; i++) {
// elems may not be aligned, read with memcpy
uint32_t elem;
Expand Down
11 changes: 6 additions & 5 deletions src/roaring64.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ roaring64_bitmap_t *roaring64_bitmap_of_ptr(size_t n_args,

roaring64_bitmap_t *roaring64_bitmap_of(size_t n_args, ...) {
roaring64_bitmap_t *r = roaring64_bitmap_create();
roaring64_bulk_context_t context = {0};
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
va_list ap;
va_start(ap, n_args);
for (size_t i = 0; i < n_args; i++) {
Expand Down Expand Up @@ -317,7 +317,7 @@ void roaring64_bitmap_add_many(roaring64_bitmap_t *r, size_t n_args,
return;
}
const uint64_t *end = vals + n_args;
roaring64_bulk_context_t context = {0};
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
for (const uint64_t *current_val = vals; current_val != end;
current_val++) {
roaring64_bitmap_add_bulk(r, &context, *current_val);
Expand Down Expand Up @@ -456,7 +456,8 @@ bool roaring64_bitmap_contains_bulk(const roaring64_bitmap_t *r,
uint8_t high48[ART_KEY_BYTES];
uint16_t low16 = split_key(val, high48);

if (context->leaf == NULL || context->high_bytes != high48) {
if (context->leaf == NULL ||
art_compare_keys(context->high_bytes, high48) != 0) {
// We're not positioned anywhere yet or the high bits of the key
// differ.
leaf_t *leaf = (leaf_t *)art_find(&r->art, high48);
Expand Down Expand Up @@ -640,7 +641,7 @@ void roaring64_bitmap_remove_many(roaring64_bitmap_t *r, size_t n_args,
return;
}
const uint64_t *end = vals + n_args;
roaring64_bulk_context_t context = {0};
roaring64_bulk_context_t context = {0, 0, 0, 0, 0, 0, 0};
for (const uint64_t *current_val = vals; current_val != end;
current_val++) {
roaring64_bitmap_remove_bulk(r, &context, *current_val);
Expand Down Expand Up @@ -1968,7 +1969,7 @@ bool roaring64_bitmap_iterate(const roaring64_bitmap_t *r,

void roaring64_bitmap_to_uint64_array(const roaring64_bitmap_t *r,
uint64_t *out) {
roaring64_iterator_t it = {0};
roaring64_iterator_t it; // gets initialized in the next line
roaring64_iterator_init_at(r, &it, /*first=*/true);
roaring64_iterator_read(&it, out, UINT64_MAX);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/toplevel_unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ DEFINE_TEST(range_contains) {

DEFINE_TEST(contains_bulk) {
roaring_bitmap_t *bm = roaring_bitmap_create();
roaring_bulk_context_t context = {0};
roaring_bulk_context_t context = {0, 0, 0, 0};

// Ensure checking an empty bitmap is okay
assert_true(!roaring_bitmap_contains_bulk(bm, &context, 0));
Expand Down Expand Up @@ -176,7 +176,7 @@ DEFINE_TEST(contains_bulk) {
size_t test_count = sizeof(values) / sizeof(values[0]);

for (size_t i = 0; i < test_count; i++) {
roaring_bulk_context_t empty_context = {0};
roaring_bulk_context_t empty_context = {0, 0, 0, 0};
bool expected_contains = roaring_bitmap_contains(bm, values[i]);
assert_true(expected_contains == roaring_bitmap_contains_bulk(
bm, &empty_context, values[i]));
Expand Down Expand Up @@ -1055,7 +1055,7 @@ DEFINE_TEST(test_addremove) {

DEFINE_TEST(test_addremove_bulk) {
roaring_bitmap_t *bm = roaring_bitmap_create();
roaring_bulk_context_t context = {0};
roaring_bulk_context_t context = {0, 0, 0, 0};
for (uint32_t value = 33057; value < 147849; value += 8) {
roaring_bitmap_add_bulk(bm, &context, value);
}
Expand Down

0 comments on commit 44228a0

Please sign in to comment.