Skip to content

refactor(countmin): encapsulate bucket count state - #301

Merged
tisonkun merged 3 commits into
apache:mainfrom
tisonkun:refactor/countmin-bucket-count
Oct 24, 2026
Merged

tisonkun merged 3 commits into
apache:mainfrom
tisonkun:refactor/countmin-bucket-count

Conversation

@tisonkun

@tisonkun tisonkun commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #300 (comment).

Summary

  • Introduce a private BucketCount to keep the bucket count and its precomputed remainder multiplier together.
  • Move power-of-two masking and exact remainder reduction behind BucketCount::index.
  • Preserve the public API, serialized bytes, and exact bucket assignment.

Trade-off

On the current 64-bit target, nesting the u32 count and u128 multiplier increases CountMinSketch from 96 to 112 bytes because the outer type cannot reuse the nested type's tail padding. Under main's existing inline-plus-heap convention, this also increases estimated_size() by 16 bytes per sketch. #302 independently makes estimated_size implementation-dependent; its current Count-Min implementation excludes this inline overhead.

Validation

  • cargo x check
  • cargo x test
  • cargo x lint

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll push a follow-up for change the estimated_size impl for mainly heap size.

@tisonkun
tisonkun merged commit 28769d4 into apache:main Oct 24, 2026
10 checks passed
@tisonkun

Copy link
Copy Markdown
Member Author

Review after commit is welcome.

I'm glad to accept any better writing.

@tisonkun
tisonkun deleted the refactor/countmin-bucket-count branch October 24, 2026 02:02
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.

1 participant