Skip to content

feat(sketchdb): CMS-with-heap top-K accuracy bound - #57

Merged
zzylol merged 1 commit into
mainfrom
feat/sketchdb-accuracy-cms-with-heap-topk
Apr 21, 2026
Merged

zzylol merged 1 commit into
mainfrom
feat/sketchdb-accuracy-cms-with-heap-topk

Conversation

@zzylol

@zzylol zzylol commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Splits CountMinSketchWithHeap from plain CMS in the accuracy derivation; gives it a top-K retention bound from Metwally-Agrawal-El Abbadi (ICDT 2005) alongside the Cormode-Muthukrishnan CMS point-lookup bound. New AccuracyKind::TopK variant. ε = max(e/w, 1/heap_size), δ = 1/2^d. +4 tests, 788 green, clippy + fmt clean.

Splits `CountMinSketchWithHeap` out of the plain-CMS branch in
`AccuracyProfile::derive` and gives it its own bound:

  * per-item frequency: e/w    (CMS, Cormode-Muthukrishnan 2005)
  * top-K retention:    1/k    (Metwally et al., ICDT 2005)
  → reported ε = max(e/w, 1/k); δ = 1/2^d (CMS depth)
  → new `AccuracyKind::TopK` variant (serialised as "top_k")

Heap size `k` is read from `parameters.heap_size` (or aliases
`topk` / `k`), default 100.

## Why split

Plain CMS has *per-key point-lookup* accuracy; CMS-with-heap
further guarantees *top-K retention* — items with true
frequency ≥ N·ε are guaranteed to be in the returned heap.
Conflating the two bounds under `AdditiveFrequency` lost the
retention guarantee, which is what users actually query the
heap for.

## Tests

+4 on top of #55's 5:

  cms_with_heap_carries_top_k_kind_and_heap_bound
  cms_with_heap_cms_bound_dominates_when_heap_is_generous
  cms_with_heap_uses_default_heap_size_100
  cms_with_heap_accepts_alternative_param_names

784 → 788 lib tests green; clippy + fmt clean.
@zzylol
zzylol merged commit 503292e into main Apr 21, 2026
@zzylol
zzylol deleted the feat/sketchdb-accuracy-cms-with-heap-topk branch May 9, 2026 18:00
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