Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(roaring64): art_find_at would return the wrong leaf #553

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/art/art.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ static art_val_t *art_find_at(const art_node_t *node,
depth += inner_node->prefix_size + 1;
}
art_leaf_t *leaf = CAST_LEAF(node);
if (depth >= ART_KEY_BYTES - 1) {
if (depth >= ART_KEY_BYTES) {
return (art_val_t *)leaf;
}
uint8_t common_prefix =
Expand Down
10 changes: 10 additions & 0 deletions tests/roaring64_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ DEFINE_TEST(test_add_range_closed) {
// Range spans more than two containers.
roaring64_bitmap_t* r = roaring64_bitmap_create();
roaring64_bitmap_add_range_closed(r, 100, 300000);
assert_int_equal(roaring64_bitmap_get_cardinality(r), 300000 - 100 + 1);
roaring64_bulk_context_t context{};
assert_false(roaring64_bitmap_contains_bulk(r, &context, 99));
for (uint64_t i = 100; i <= 300000; ++i) {
Expand All @@ -223,6 +224,15 @@ DEFINE_TEST(test_add_range_closed) {
assert_true(roaring64_bitmap_contains(r, 100));
roaring64_bitmap_free(r);
}
{
// Add a range that spans multiple ART levels (end >> 16 == 0x0101)
roaring64_bitmap_t* r = roaring64_bitmap_create();
uint64_t end = 0x101ffff;
uint64_t start = 0;
roaring64_bitmap_add_range_closed(r, start, end);
assert_int_equal(roaring64_bitmap_get_cardinality(r), end - start + 1);
roaring64_bitmap_free(r);
}
}

DEFINE_TEST(test_contains_bulk) {
Expand Down