sketch_space_saving.nx
buildroot/runtime/sketch_space_saving.nx
about
sketch_space_saving.nx -- SpaceSaving top-K heavy hitters.
Metwally-Agrawal-El-Abbadi 2005. Bounded set of (key, count,
error) triples of capacity K. On add: if key tracked, increment;
else if room, insert with count=1, error=0; else evict the
minimum-count entry and install (new_key, min_count + count,
min_count).
Guarantee: any item with true frequency > N/K is tracked (no
false negatives for heavy hitters). The reported count
over-estimates by at most `error`; true_count is in
[count - error, count] for tracked items.
COMPLEMENTS CMS:
- CMS: per-query frequency for ANY key (overestimate-only).
- SpaceSaving: enumerate the top-K most frequent keys directly.
Together they cover the full frequency-counting axis.
API takes i64 keys (caller hashes strings to i64 via murmur3 if
they have string-keyed streams).
LOSSLESS-LANGUAGE DISCIPLINE (doc 20):
nx_ss_query returns ApproxI64 with envelope_kind = NX_ENV_ABS;
param_a holds the per-key error bound (count - error <= true <=
count); conf_ppb = 1e9 (deterministic; not probabilistic).
dependencies 2 imports · 2 importers
imports: syscalls.nxsketch_types.nx
imported by: sketch_mg_ss_bracket_bench.nxsketch_space_saving_test.nx
structs
| 34 | struct SsCounter { |
| 40 | struct SpaceSaving { |
consts
| 30 | const NX_SS_K_MIN: i64 = 2 |
| 31 | const NX_SS_K_MAX: i64 = 100000 |
functions
| 49 | func nx_ss_alloc(k: i64) -> *SpaceSaving { |
| 65 | func nx_ss_find_key(s: *SpaceSaving, key: i64) -> i64 { |
| 76 | func nx_ss_find_min(s: *SpaceSaving) -> i64 {
called by 1: nx_ss_add |
| 97 | func nx_ss_add(s: *SpaceSaving, key: i64, count: i64) -> i64 { |
| 126 | func nx_ss_estimate(s: *SpaceSaving, key: i64) -> i64 { |
| 133 | func nx_ss_lower_bound(s: *SpaceSaving, key: i64) -> i64 { |
| 140 | func nx_ss_error(s: *SpaceSaving, key: i64) -> i64 { |
| 149 | func nx_ss_max_overcount(s: *SpaceSaving) -> i64 {
called by 1: nx_ss_query |
| 153 | func nx_ss_query(s: *SpaceSaving, key: i64) -> *ApproxI64 { |
| 167 | func if_min(a: i64, b: i64) -> i64 {
called by 1: nx_ss_top_k |
| 172 | func nx_ss_top_k(s: *SpaceSaving, n: i64, out_keys: *i64, out_counts: *i64) -> i64 { |
| 218 | func nx_ss_memory_bytes(s: *SpaceSaving) -> i64 { |