code wiki / (root) / sketch_hllmap.nx

sketch_hllmap.nx

buildroot/runtime/sketch_hllmap.nx

8404 B245 linesdepth 6pulls 11 transitivereach 2 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_hllmap.nx -- Map<key, HLL> for "distinct count per key" queries. E.g. distinct-IPs-per-URL, distinct-events-per-user, distinct-terms- per-document. Compose a hash map with the HLL primitive: each map entry holds a separate HLL sketch. CAPABILITY STOMP vs DataSketches: DS HllMap supports add + estimate but does NOT support merge of two HllMaps (their docs flag this as future work). We ship merge on day one because: - HLL merge is register-wise max (cheap) - hash-map merge is set-union of keys (linear) together they compose without state surgery. Hash table: linear-probing, power-of-2 capacity, open addressing. Entry = {key_hash: i64, hll: *Hll}. Empty slots: key_hash == 0 (we map true-hash 0 -> 1 to avoid collision with the empty sentinel). Per the lossless-language doctrine: per-key estimates ship the same Approximate<i64> envelope as base HLL (rel_stddev = 1.04/sqrt(m)).

dependencies 4 imports · 2 importers

syscalls.nx murmur3.nx sketch_hll.nx sketch_types.nx sketch_hllmap.nx sketch_hllmap_merge_capability_ben sketch_hllmap_test.nx

imports: syscalls.nxmurmur3.nxsketch_hll.nxsketch_types.nx

imported by: sketch_hllmap_merge_capability_bench.nxsketch_hllmap_test.nx

structs

31struct HllMapEntry {
36struct HllMap {

consts

28const NX_HMAP_EMPTY: i64 = 0
29const NX_HMAP_LF_MAX_PCT: i64 = 70 // resize at >70% load

functions

46func nx_hmap_is_pow2(n: i64) -> i64 {
called by 1: nx_hllmap_alloc
52func nx_hllmap_alloc(capacity: i64, lg_k: i64, seed: i64) -> *HllMap {
75func nx_hmap_entry_at(m: *HllMap, i: i64) -> *HllMapEntry {
85func nx_hllmap_probe(m: *HllMap, key_hash: i64) -> i64 {
115func nx_hllmap_key_hash(m: *HllMap, key: *u8, len: i64) -> i64 {
121func nx_hllmap_add(m: *HllMap, key: *u8, key_len: i64,
140func nx_hllmap_estimate(m: *HllMap, key: *u8, key_len: i64) -> i64 {
148func nx_hllmap_query(m: *HllMap, key: *u8, key_len: i64) -> *ApproxI64 {
167func nx_hllmap_max2(x: i64, y: i64) -> i64 {
called by 1: nx_hllmap_merge
174func nx_hllmap_clone_hll(src: *Hll) -> *Hll {
called by 1: nx_hllmap_merge calls 1: nx_hll_alloc
184func nx_hllmap_merge(a: *HllMap, b: *HllMap) -> *HllMap {
236func nx_hllmap_memory_bytes(m: *HllMap) -> i64 {
243func nx_hllmap_n_entries(m: *HllMap) -> i64 {
called by 1: main