feat: expose estimated_size for stateful set operations - #177
Merged
Conversation
Cover the accumulating set-operation operators that hold real heap state: HllUnion, CpcUnion, ThetaUnion, ThetaIntersection, TupleUnion, and TupleIntersection. The a-not-b operators are stateless and thus exempt. UnionState and IntersectionState in thetacommon gain heap-only helpers that delegate to SketchHashTable, mirroring the sketch-level pattern from apache#136. For HllUnion and CpcUnion, whose state embeds a full sketch inline, the sketch's inline size is subtracted to avoid double counting against size_of::<Self>(). Addresses apache#137
tisonkun
reviewed
Aug 2, 2026
Comment on lines
+183
to
+195
| #[test] | ||
| fn test_union_estimated_size() { | ||
| let mut union = CpcUnion::new(11); | ||
| let empty_size = union.estimated_size(); | ||
| assert!(empty_size > 0); | ||
|
|
||
| let mut sketch = CpcSketch::new(11); | ||
| for i in 0..1000 { | ||
| sketch.update(i); | ||
| } | ||
| union.update(&sketch); | ||
| assert!(union.estimated_size() > empty_size); | ||
| } |
Member
There was a problem hiding this comment.
Please try to follow 05b5ad5 to assert exact values of estimated_size.
tisonkun
reviewed
Aug 2, 2026
tisonkun
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution @Renkai!
Looks like a good suppliment.
cc @notfilippo @ariesdevil FYI you may review how HllSktech and ThetaSketch/TupleSketch provides their estimated size.
Comments inline above.
Signed-off-by: Renkai Ge <gaelookair@gmail.com>
Renkai
force-pushed
the
feat/estimated-size-set-operations
branch
from
August 4, 2026 13:50
d588da7 to
65132ef
Compare
Renkai
marked this pull request as ready for review
August 4, 2026 13:52
Contributor
Author
|
updated |
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.
Follow-up of #174, addressing part of #137.
While all sketch types expose
estimated_size()now, the stateful set-operation operators — which hold real heap state while accumulating updates — don't report their footprint yet. This patch addsestimated_size()to:HllUnion— delegates to its internalHllSketchgadgetCpcUnion— covers both internal states (Accumulatorsketch andBitMatrix)ThetaUnion/ThetaIntersection— via a heap-only helper onUnionState/IntersectionStateTupleUnion/TupleIntersection— same shared helpersThe a-not-b operators are stateless (a one-shot computation over two inputs), so they are intentionally exempt.
Implementation notes:
UnionState::estimated_size()/IntersectionState::estimated_size()report heap allocations only (delegating toSketchHashTable::estimated_size()), so the public operators can composesize_of::<Self>() + state.estimated_size()without double counting.HllUnionandCpcUnion, whose state embeds a full sketch inline, the inner sketch's inline size is subtracted for the same reason.Note that an operator's footprint cannot be inferred from its result sketch: the internal table keeps capacity headroom per its load factor and resize history (and
CpcUnion's bit matrix is fixed atk * 8bytes), whereasto_sketch()produces a tightly packed copy.Tests: one case per operator in the existing integration targets. Verified with
cargo x check,cargo x test(incl. Go snapshots), andcargo x lint.