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

Simplify, and optimize roaring64_bitmap_remove_range_closed #592

Merged
merged 1 commit into from
Feb 17, 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
17 changes: 6 additions & 11 deletions src/roaring64.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,17 +696,12 @@ void roaring64_bitmap_remove_range_closed(roaring64_bitmap_t *r, uint64_t min,
// Remove a range across containers. Remove intermediate containers
// entirely.
remove_range_closed_at(art, min_high48, min_low16, 0xffff);
uint64_t min_high_bits = min >> 16;
uint64_t max_high_bits = max >> 16;
for (uint64_t current = min_high_bits + 1; current < max_high_bits;
++current) {
uint8_t current_high48[ART_KEY_BYTES];
split_key(current << 16, current_high48);
leaf_t *leaf = (leaf_t *)art_erase(art, current_high48);
if (leaf != NULL) {
container_free(leaf->container, leaf->typecode);
free_leaf(leaf);
}

art_iterator_t it = art_upper_bound(art, min_high48);
while (it.value != NULL && art_compare_keys(it.key, max_high48) < 0) {
leaf_t *leaf = (leaf_t *)art_iterator_erase(art, &it);
container_free(leaf->container, leaf->typecode);
free_leaf(leaf);
}
remove_range_closed_at(art, max_high48, 0, max_low16);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/roaring64_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,12 @@ DEFINE_TEST(test_remove_range_closed) {
assert_int_equal(roaring64_bitmap_maximum(r), UINT64_MAX - 6);
roaring64_bitmap_free(r);
}
{
// Remove a huge range
roaring64_bitmap_t* r = roaring64_bitmap_from(1, UINT64_MAX - 1);
roaring64_bitmap_remove_range_closed(r, 0, UINT64_MAX);
roaring64_bitmap_free(r);
}
}

DEFINE_TEST(test_get_cardinality) {
Expand Down
Loading