code wiki / (root) / nx_sketch_tuple.nx

nx_sketch_tuple.nx

buildroot/runtime/nx_sketch_tuple.nx

11249 B328 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_tuple.nx -- Tuple sketch (Theta + per-hash auxiliary data). Extends the Theta sketch family by attaching a SCALAR value to each hash slot. Use cases (matching DataSketches Tuple docs): - sum-of-revenue across distinct users (one (hash, revenue) per user) - max-recency across distinct items - count-of-events-per-distinct-user Multiple inserts of the same hash combine via a CALLER-CHOSEN reducer: NX_TUPLE_RED_SUM — add (default for revenue / counts) NX_TUPLE_RED_MAX — keep larger (for recency / peak) NX_TUPLE_RED_MIN — keep smaller (for first-seen / earliest) NX_TUPLE_RED_REPLACE— overwrite (last-write-wins) THETA + AGGREGATE ESTIMATOR: E[sum_over_set] ≈ (sum_over_sample) * HASH_MAX / theta where the sum_over_sample is over the values < theta currently stored. Theta-corrected like Theta cardinality estimator. MERGE (capability beyond DataSketches Tuple-merge spec): - theta_out = min(theta_a, theta_b) - hashes_out = K smallest across union, filtered to < theta_out - value_out for each surviving hash = reducer(a.val, b.val) if both have it, else whichever side had it.

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_murmur3.nx nx_sketch_types.nx nx_sketch_tuple.nx

imports: nx_syscalls.nxnx_murmur3.nxnx_sketch_types.nx

imported by: nobody (leaf or entry point)

structs

43struct TupleEntry
48struct TupleSketch

consts

36const NX_TUPLE_HASH_MAX: i64 = 4294967296
38const NX_TUPLE_RED_SUM: i64 = 0
39const NX_TUPLE_RED_MAX: i64 = 1
40const NX_TUPLE_RED_MIN: i64 = 2
41const NX_TUPLE_RED_REPLACE: i64 = 3

functions

59func nx_tuple_reduce(reducer: i64, a: i64, b: i64) -> i64
74func nx_tuple_alloc(k: i64, seed: i64, reducer: i64) -> *TupleSketch
called by 1: nx_tuple_merge calls 1: sys_mmap
91func nx_tuple_entry_at(t: *TupleSketch, i: i64) -> *TupleEntry
97func nx_tuple_add(t: *TupleSketch, key: *u8, key_len: i64, value: i64) -> i64
163func nx_tuple_aggregate(t: *TupleSketch) -> i64
189func nx_tuple_cardinality(t: *TupleSketch) -> i64
205func nx_tuple_stddev_rel_ppb(k: i64) -> i64
215func nx_tuple_query_aggregate(t: *TupleSketch) -> *ApproxI64
224func nx_tuple_query_cardinality(t: *TupleSketch) -> *ApproxI64
238func nx_tuple_min2(a: i64, b: i64) -> i64
called by 1: nx_tuple_merge
243func nx_tuple_merge(a: *TupleSketch, b: *TupleSketch) -> *TupleSketch
326func nx_tuple_memory_bytes(t: *TupleSketch) -> i64