nx_sketch_space_saving.nx
buildroot/runtime/nx_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 · 0 importers
imports: nx_syscalls.nxnx_sketch_types.nx
imported by: nobody (leaf or entry point)
structs
| 40 | struct SsCounter |
| 46 | struct SpaceSaving |
consts
| 36 | const NX_SS_K_MIN: i64 = 2 |
| 37 | const NX_SS_K_MAX: i64 = 100000 |
functions
| 55 | func nx_ss_alloc(k: i64) -> *SpaceSaving calls 1: sys_mmap |
| 71 | func nx_ss_find_key(s: *SpaceSaving, key: i64) -> i64 |
| 82 | func nx_ss_find_min(s: *SpaceSaving) -> i64 called by 1: nx_ss_add |
| 103 | func nx_ss_add(s: *SpaceSaving, key: i64, count: i64) -> i64 |
| 132 | func nx_ss_estimate(s: *SpaceSaving, key: i64) -> i64 |
| 139 | func nx_ss_lower_bound(s: *SpaceSaving, key: i64) -> i64 calls 1: nx_ss_find_key |
| 146 | func nx_ss_error(s: *SpaceSaving, key: i64) -> i64 calls 1: nx_ss_find_key |
| 155 | func nx_ss_max_overcount(s: *SpaceSaving) -> i64 called by 1: nx_ss_query |
| 159 | func nx_ss_query(s: *SpaceSaving, key: i64) -> *ApproxI64 |
| 173 | func if_min(a: i64, b: i64) -> i64 called by 1: nx_ss_top_k |
| 178 | func nx_ss_top_k(s: *SpaceSaving, n: i64, out_keys: *i64, out_counts: *i64) -> i64 |
| 224 | func nx_ss_memory_bytes(s: *SpaceSaving) -> i64 |