nx_sketch_tuple.nx
buildroot/runtime/nx_sketch_tuple.nx
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
imports: nx_syscalls.nxnx_murmur3.nxnx_sketch_types.nx
imported by: nobody (leaf or entry point)
structs
| 43 | struct TupleEntry |
| 48 | struct TupleSketch |
consts
| 36 | const NX_TUPLE_HASH_MAX: i64 = 4294967296 |
| 38 | const NX_TUPLE_RED_SUM: i64 = 0 |
| 39 | const NX_TUPLE_RED_MAX: i64 = 1 |
| 40 | const NX_TUPLE_RED_MIN: i64 = 2 |
| 41 | const NX_TUPLE_RED_REPLACE: i64 = 3 |
functions
| 59 | func nx_tuple_reduce(reducer: i64, a: i64, b: i64) -> i64 |
| 74 | func nx_tuple_alloc(k: i64, seed: i64, reducer: i64) -> *TupleSketch |
| 91 | func nx_tuple_entry_at(t: *TupleSketch, i: i64) -> *TupleEntry |
| 97 | func nx_tuple_add(t: *TupleSketch, key: *u8, key_len: i64, value: i64) -> i64 |
| 163 | func nx_tuple_aggregate(t: *TupleSketch) -> i64 |
| 189 | func nx_tuple_cardinality(t: *TupleSketch) -> i64 |
| 205 | func nx_tuple_stddev_rel_ppb(k: i64) -> i64 |
| 215 | func nx_tuple_query_aggregate(t: *TupleSketch) -> *ApproxI64 |
| 224 | func nx_tuple_query_cardinality(t: *TupleSketch) -> *ApproxI64 |
| 238 | func nx_tuple_min2(a: i64, b: i64) -> i64 called by 1: nx_tuple_merge |
| 243 | func nx_tuple_merge(a: *TupleSketch, b: *TupleSketch) -> *TupleSketch |
| 326 | func nx_tuple_memory_bytes(t: *TupleSketch) -> i64 |