Repository navigation
roaring64: compare sign-extended planes in BSI Equals - #613
Merged
Merged
Conversation
Equals compared the planes of the wider BSI past the top of the narrower one against an empty plane. That is only right when the narrower BSI holds no negative values. Two BSIs of different widths holding the same negative value compared unequal, and a 2-plane BSI holding -1 compared equal to a 3-plane BSI holding 3, since their two low planes match. Compare each plane past the top of a BSI against its sign plane instead.
Keep the sign-extension Equals tests and the tests already on master.
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.
Bug
BSI.Equalshandled BSIs of different widths by requiring the extra planes of the wider one to be empty. That is only right when the narrower BSI holds no negative values. In two's complement, a BSI's planes past its top repeat its sign plane. This causes two errors:False negative: the same negative value at two widths compares unequal.
False positive: a 2-plane BSI holding
-1(planes11) and a 3-plane BSI holding3(planes011) compare equal, because their two low planes match and the third plane of the wider one is empty.Different widths are common. They come from
NewBSIbounds, fromSetValuewidening an auto-sized BSI, and fromAdd.Fix
Compare the planes sign-extended to the wider width: past the top of a BSI, its sign plane is used. A BSI with no planes counts as all zeros. When neither BSI holds a negative value this is the same as before, and BSIs of the same width are compared exactly as before.
Testing
TestEqualsDifferentWidthscovers:-1vs3false positive, at mixed widths and at one width;-1.On master, the test fails on both the false-negative and the false-positive checks.
go test ./roaring64,go vetandgofmtpass.