Skip to content

Commit

Permalink
Fix r64 contains range when max is divisible by 2^16 (RoaringBitmap#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
SLieve committed Feb 3, 2024
1 parent 3fa841d commit cff6a0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit cff6a0e

Please sign in to comment.