code wiki / (root) / sketch_tuple.nx

sketch_tuple.nx

buildroot/runtime/sketch_tuple.nx

11311 B322 linesdepth 4pulls 5 transitivereach 1 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 · 1 importers

syscalls.nx murmur3.nx sketch_types.nx sketch_tuple.nx sketch_tuple_test.nx

imports: syscalls.nxmurmur3.nxsketch_types.nx

imported by: sketch_tuple_test.nx

structs

37struct TupleEntry {
42struct TupleSketch {

consts

30const NX_TUPLE_HASH_MAX: i64 = 4294967296
32const NX_TUPLE_RED_SUM: i64 = 0
33const NX_TUPLE_RED_MAX: i64 = 1
34const NX_TUPLE_RED_MIN: i64 = 2
35const NX_TUPLE_RED_REPLACE: i64 = 3

functions

53func nx_tuple_reduce(reducer: i64, a: i64, b: i64) -> i64 {
68func nx_tuple_alloc(k: i64, seed: i64, reducer: i64) -> *TupleSketch {
called by 2: nx_tuple_mergemain
85func nx_tuple_entry_at(t: *TupleSketch, i: i64) -> *TupleEntry {
91func nx_tuple_add(t: *TupleSketch, key: *u8, key_len: i64, value: i64) -> i64 {
157func nx_tuple_aggregate(t: *TupleSketch) -> i64 {
183func nx_tuple_cardinality(t: *TupleSketch) -> i64 {
199func nx_tuple_stddev_rel_ppb(k: i64) -> i64 {
209func nx_tuple_query_aggregate(t: *TupleSketch) -> *ApproxI64 {
218func nx_tuple_query_cardinality(t: *TupleSketch) -> *ApproxI64 {
232func nx_tuple_min2(a: i64, b: i64) -> i64 {
called by 1: nx_tuple_merge
237func nx_tuple_merge(a: *TupleSketch, b: *TupleSketch) -> *TupleSketch {
320func nx_tuple_memory_bytes(t: *TupleSketch) -> i64 {