code wiki / (root) / nx_sketch_misra_gries.nx

nx_sketch_misra_gries.nx

buildroot/runtime/nx_sketch_misra_gries.nx

7420 B231 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_misra_gries.nx -- Misra-Gries frequent items (1982). Bounded set of (key, count) pairs of capacity (k-1). On arrival of (key, w): - if key tracked: count[key] += w - else if free slot: install (key, w) - else: decrement EVERY counter by w (with floor 0); counters that reach 0 are freed for future use GUARANTEE (different from SpaceSaving): true_count - N/k <= estimate <= true_count Misra-Gries UNDERESTIMATES; SpaceSaving OVERESTIMATES. Both bound the error by N/k. Symmetric error semantics let callers pick: - SpaceSaving for upper-bound queries ("at most X") - Misra-Gries for lower-bound queries ("at least X") CAPABILITY STOMP vs DataSketches: DS ships only the "frequent items" variant (SpaceSaving-like). We ship BOTH algorithmic approaches (SpaceSaving + Misra-Gries) so callers pick by error-bound direction. LOSSLESS-LANGUAGE DISCIPLINE: nx_mg_query returns ApproxI64 with NX_ENV_ABS; param_a = N/k (the maximum possible UNDERESTIMATE); conf_ppb = 1e9 (deterministic).

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_sketch_types.nx nx_sketch_misra_gries.nx

imports: nx_syscalls.nxnx_sketch_types.nx

imported by: nobody (leaf or entry point)

structs

38struct MgCounter
43struct MisraGries

consts

35const NX_MG_K_MIN: i64 = 2
36const NX_MG_K_MAX: i64 = 100000

functions

52func nx_mg_alloc(k: i64) -> *MisraGries
calls 1: sys_mmap
73func nx_mg_counter_at(mg: *MisraGries, i: i64) -> *MgCounter
79func nx_mg_find_key(mg: *MisraGries, key: i64) -> i64
89func nx_mg_find_empty(mg: *MisraGries) -> i64
called by 1: nx_mg_add calls 1: nx_mg_counter_at
112func if_le(a: i64, b: i64) -> i64
called by 1: nx_mg_add
117func nx_mg_min_count(mg: *MisraGries) -> i64
called by 1: nx_mg_add calls 1: nx_mg_counter_at
130func nx_mg_add(mg: *MisraGries, key: i64, count: i64) -> i64
190func nx_mg_estimate(mg: *MisraGries, key: i64) -> i64
199func nx_mg_max_undercount(mg: *MisraGries) -> i64
204func nx_mg_upper_bound(mg: *MisraGries, key: i64) -> i64
208func nx_mg_query(mg: *MisraGries, key: i64) -> *ApproxI64
218func nx_mg_n_tracked(mg: *MisraGries) -> i64
229func nx_mg_memory_bytes(mg: *MisraGries) -> i64