Skip to content

Fix CpcWrapper throwing on empty sketches - #757

Merged
leerho merged 1 commit into
apache:mainfrom
permutive-engineering:fix/cpc-wrapper-empty-sketch
Sep 2, 2026
Merged

Fix CpcWrapper throwing on empty sketches#757
leerho merged 1 commit into
apache:mainfrom
permutive-engineering:fix/cpc-wrapper-empty-sketch

Conversation

@davecromberge

Copy link
Copy Markdown
Member

CpcWrapper.getEstimate(), getLowerBound() and getUpperBound() throw
SketchesStateException for any empty sketch, so the class can't be used by a caller
whose data may contain one.

An empty image carries none of the high preamble fields. EMPTY_HIP sets the HIP flag, so
getEstimate() takes the HIP branch and asks for HIP_ACCUM; EMPTY_MERGED takes the ICON
branch and asks for NUM_COUPONS. Neither field is present, so both throw.

Empty now reports zero coupons and a zero HIP accumulator, matching CpcSketch.

Added CpcWrapperEquivalenceTest, which checks the wrapper against a heapified sketch on
estimate, both bounds and lgK, across every lgK, the coupon counts that drive the flavor
transitions, union results, and the three ways a sketch can be empty.

An empty CPC image carries none of the high preamble fields, but getEstimate()
and the two bound methods read them regardless, so every empty sketch throws
SketchesStateException. Empty now reports zero coupons and a zero HIP
accumulator, matching what CpcSketch reports.

@leerho leerho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@leerho
leerho merged commit b994503 into apache:main Sep 2, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants