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 r64 contains range when max is divisible by 2^16 #576

Merged
merged 1 commit into from
Jan 28, 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/roaring64.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ bool roaring64_bitmap_contains_range(const roaring64_bitmap_t *r, uint64_t min,
uint16_t min_low16 = split_key(min, min_high48);
uint8_t max_high48[ART_KEY_BYTES];
uint16_t max_low16 = split_key(max, max_high48);
uint64_t max_high48_bits = max & 0xFFFFFFFFFFFF0000;
uint64_t max_high48_bits = (max - 1) & 0xFFFFFFFFFFFF0000; // Inclusive

art_iterator_t it = art_lower_bound(&r->art, min_high48);
if (it.value == NULL || combine_key(it.key, 0) > min) {
Expand Down
20 changes: 19 additions & 1 deletion tests/roaring64_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ DEFINE_TEST(test_contains_range) {
// Range larger than bitmap.
roaring64_bitmap_t* r = roaring64_bitmap_create();
roaring64_bitmap_add_range(r, 1, 1 << 16);
assert_false(roaring64_bitmap_contains_range(r, 1, (1 << 16)));
assert_false(roaring64_bitmap_contains_range(r, 1, (1 << 16) + 1));
roaring64_bitmap_free(r);
}
{
Expand All @@ -329,6 +329,24 @@ DEFINE_TEST(test_contains_range) {
roaring64_bitmap_contains_range(r, 2 << 16, (2 << 16) + 1));
roaring64_bitmap_free(r);
}
{
// Range exactly containing the last value in a container range.
roaring64_bitmap_t* r = roaring64_bitmap_create();
roaring64_bitmap_add(r, (1 << 16) - 1);
assert_true(
roaring64_bitmap_contains_range(r, (1 << 16) - 1, (1 << 16)));
assert_false(
roaring64_bitmap_contains_range(r, (1 << 16) - 1, (1 << 16) + 1));
roaring64_bitmap_free(r);
}
{
// Range exactly containing the first value in a container range.
roaring64_bitmap_t* r = roaring64_bitmap_create();
roaring64_bitmap_add(r, (1 << 16));
assert_true(
roaring64_bitmap_contains_range(r, (1 << 16), (1 << 16) + 1));
roaring64_bitmap_free(r);
}
}

DEFINE_TEST(test_select) {
Expand Down
Loading