Repository navigation
fix: start an empty deserialized sketch from a valid HIP state - #579
Merged
Merged
Conversation
leerho
approved these changes
Nov 15, 2026
leerho
left a comment
Member
There was a problem hiding this comment.
Approve. The fix is correct and matches Java.
- The bug: a never-merged empty CPC sketch is serialized with its HIP flag set but without the HIP fields. Those are only written alongside a table or window. So the reader left kxp at 0, and the first update after deserializing computed k / kxp, which made the estimate infinite.
- The fix: start kxp at 1 << lg_k, the same value a new sketch’s constructor uses, and the same as Java’s CompressedState. Images that carry the HIP fields still overwrite it.
- Testing: I merged it with current master. All 52 CPC test cases pass under ASan and UBSan, and so do the Java-file tests, including its new cpc_n0_java.sk case. Its new test fails on master’s code with exactly the bug: an estimate of inf instead of 997.6.
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.
Empty sketch has no HIP value.
So during deserialization, we should start kxp as 2^lgk.
If not, after deserialization and then update some value then estimation become inf.