Deprecate BloomFilter.invert and add difference (A NOT B) - #768
Merged
leerho merged 1 commit intoSep 17, 2026
Merged
Conversation
invert() flips bits but has no sound set-membership reading; the only composition with a clean per-item meaning is A AND NOT B. Add BloomFilter.difference (bitwise AND-NOT), deprecate invert(), and mirror the BitArray change as andNot. Aligns with datasketches-rust apache#278. Fixes apache#766.
leerho
approved these changes
Sep 17, 2026
leerho
left a comment
Member
There was a problem hiding this comment.
Thank you for looking at this!
And fixing it!
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.
Fixes #766.
Summary
BloomFilter.invert()flips the backing bit array but has no sound set-membership interpretation (see the issue). The only boolean composition involving inversion with a clean per-item meaning is A AND NOT B. This PR:BloomFilter.invert()with a pointer to the replacement.BloomFilter.difference(BloomFilter other)— bitwise AND-NOT (this &= ~other) with documented exact-exclusion / possible left-item-drop semantics.BitArray.andNot(Heap + Direct implementations; read-only throws), matchingBitSet.andNot.Aligns with the already-merged Rust change: apache/datasketches-rust#278. Wire format unchanged.
differencesemanticsotheralways queryfalse: excluded exactly.other(unlikeunion/intersect, items can drop).nullother is a no-op; incompatible filters throw (same as union/intersect).Tests
BloomFilterTest: basic difference, self-difference clears, empty right is identity, incompatibledifference; tightened deprecatedinversionTest(inserted items are always absent after invert).HeapBitArrayTest/DirectBitArrayTest:andNothappy path + length mismatch.DirectBitArrayRTest: read-onlyandNotthrows.AI disclosure
I used Cursor / Grok to help draft the patch and open this PR via the GitHub API (no local clone). Semantics follow #766 and the merged Rust
differenceAPI.