Repository navigation
Fix NextUnsetBit returning set bits in bitmap containers - #593
Merged
Merged
Conversation
NextUnsetBit shifted the word before inverting it, so the zeros shifted in at the top became ones and were taken for unset bits. When the rest of the word was all ones, it returned the first bit of the next word, which made the Unset iterator yield values present in the bitmap. Invert first, then shift, as nextAbsentValue already does. Fixes #592
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 #592.
bitmapContainer.NextUnsetBitshifted the word right before inverting it, so the zeros shifted in at the top turned into ones and were read as unset bits. Whenever the rest of the word was all ones, it returned the first bit of the next word, even if that bit was set. The bitmap container's unset iterator (Unset,UnsetIterator, includingAdvanceIfNeeded) uses this function, so it yielded values that are in the bitmap:The fix inverts first and then shifts, as
nextAbsentValuealready does (79ebb60).The
NextAbsentValue/PreviousAbsentValuepart of #592 was already fixed in v2.30.0. The report's output matches v2.29.0.Tests:
TestBitmapContainerNextUnsetBitAcrossWords:NextUnsetBiton runs of ones that cross word boundaries, and on a full container.TestUnsetBitmapContainer: the reproductions from NextAbsentValue and PreviousAbsentValue answer with a value that is present in a bitmap container #592, checked against a brute-force reference over several ranges, plusAdvanceIfNeeded.Both tests fail without the fix.
go test ./...passes.