BSI: add Retain for in-place filtering#517
Merged
lemire merged 2 commits intoRoaringBitmap:masterfrom Mar 9, 2026
Merged
Conversation
Expand the doc comment to explain: in-place semantics vs NewBSIRetainSet, why skipping bA when dropped==0 is correct (BSI consistency invariant), and when to prefer Retain over the allocating alternative. The in-place form is used in caterwaul's CleanBitmaps, which iterates every term bitmap and filters it down to currently-valid doc IDs before writing it back to storage. No new BSI allocation is needed since the result is immediately serialized.
Contributor
Author
|
Cheers |
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.
Summary
Retainis the in-place equivalent ofNewBSIRetainSet: it removes allvalues whose column IDs are not in the provided bitmap, modifying the BSI
in place and returning the number of column IDs dropped.
Prefer
RetainoverNewBSIRetainSetwhen no copy is needed — forexample when the BSI will be immediately re-serialized — as it avoids
allocating a new BSI and cloning all bit planes.
The implementation uses an optimization: if the existence bitmap is
unchanged after the intersection (i.e.
retaincovers all existing columnIDs), the bit planes are skipped entirely. This is correct because BSI
consistency guarantees that
bAcontains no set bits for column IDsabsent from
eBM.A test is included covering both the drop path and the no-op early-return.