Repository navigation
Fix bitset selection at the 32-bit rank boundary - #970
Merged
lemire merged 1 commit intoDec 1, 2026
Merged
Conversation
Signed-off-by: Perfloop Agent <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a full 32-bit bitmap,
roaring_bitmap_selectsilently returnsfalsefor every rank from0xFFFF0000throughUINT32_MAXif the final container is stored as a bitset. An equal run-compressed bitmap returns those elements.In C++, with exceptions enabled,
Roaring64Map::selectthrowsstd::runtime_error("Logic error: bitmap.select() returned false despite rank < cardinality()") for these ranks when a 32-bit sub-bitmap is full.The final container starts at rank
4294901760and contains65536values. Its exclusive end is4294967296, which wraps to zero in the old 32-bit sum. The range check now compares a widened unsigned rank difference with cardinality, avoiding the overflowing sum. Ranks below*start_ranknow return false instead of reachingassert(false). The selection loop and successful accumulator updates are unchanged.The regression in
tests/toplevel_unit.cbuilds the full bitmap with a compact run prefix and a bitset tail.tests/bitset_container_unit.cchecks end-of-domain ranks, lower-bound rejection, and the existing false-return accumulator behavior.ctest’s focused selection runs passed: three suites, zero failed, zero skipped (seven cmocka tests), in a Debug build with-DROARING_SANITIZE=ON -DROARING_SANITIZE_UNDEFINED=ON; both new tests fail without the fix.Formatting checked with clang-format 17.
AI assistance: Perfloop generated the fix, tests, and this description.
cc @lemire
Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.