fix: handle saturated bitset in ApproximatedSize#113
Open
Yanhu007 wants to merge 1 commit intobits-and-blooms:masterfrom
Open
fix: handle saturated bitset in ApproximatedSize#113Yanhu007 wants to merge 1 commit intobits-and-blooms:masterfrom
Yanhu007 wants to merge 1 commit intobits-and-blooms:masterfrom
Conversation
When all bits are set (x == m), the formula produces +Inf because log(1-x/m) = log(0) = -Inf. Converting +Inf to uint32 is undefined behavior in Go: it returns 0 on amd64 and MaxUint32 on arm64. Return math.MaxUint32 when the bitset is saturated or when the computed size overflows uint32, providing consistent cross-platform behavior. Fixes bits-and-blooms#104
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 #104
Problem
ApproximatedSize()produces+Infwhen the bitset is fully saturated (x == m), becauselog(1 - x/m) = log(0) = -Inf. Converting+Inftouint32is undefined behavior in Go:04294967295(MaxUint32)Fix
Guard against saturation and overflow:
MaxUint32when all bits are set (x >= m)MaxUint32when the computed size is+Inf,NaN, or exceedsMaxUint32This provides consistent cross-platform behavior.
All existing tests pass.