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

roaring64: container_remove_range returns null rather than returning an empty container #550

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
14 changes: 7 additions & 7 deletions src/roaring64.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@ static inline void remove_range_closed_at(art_t *art, uint8_t *high48,
leaf->container, leaf->typecode, min, max, &typecode2);
if (container2 != leaf->container) {
container_free(leaf->container, leaf->typecode);
leaf->container = container2;
leaf->typecode = typecode2;
}
if (!container_nonzero_cardinality(container2, typecode2)) {
art_erase(art, high48);
container_free(container2, typecode2);
free_leaf(leaf);
if (container2 != NULL) {
leaf->container = container2;
leaf->typecode = typecode2;
} else {
art_erase(art, high48);
free_leaf(leaf);
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/roaring64_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,21 @@ DEFINE_TEST(test_remove_range_closed) {
assert_true(roaring64_bitmap_contains_bulk(r, &context, 300000));
roaring64_bitmap_free(r);
}
{
// Range completely clears the bitmap.
roaring64_bitmap_t* r = roaring64_bitmap_create();
// array container
roaring64_bitmap_add(r, 1);
// range container
roaring64_bitmap_add_range_closed(r, 0x10000, 0x20000);
// bitmap container
for (int i = 0x20000; i < 0x25000; i += 2) {
roaring64_bitmap_add(r, i);
}
roaring64_bitmap_remove_range_closed(r, 0, 0x30000);
assert_true(roaring64_bitmap_is_empty(r));
roaring64_bitmap_free(r);
}
}

DEFINE_TEST(test_get_cardinality) {
Expand Down