code wiki / (root) / sketch_hll4.nx

sketch_hll4.nx

buildroot/runtime/sketch_hll4.nx

8862 B270 linesdepth 6pulls 11 transitivereach 2 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_hll4.nx -- HLL_4 with Heule exception table. 4 bits per register addresses rho in [0, 14]; rho = 15 is the SENTINEL meaning "see exception table for the true value." An exception table holds (idx, value) pairs for the rare registers whose true rho exceeds 14. MEMORY: HLL_4 at lg_k=10 = m/2 bytes register array + ~40 bytes header + ~0 bytes exception (lazy-allocated; most workloads never trigger). Total HLL_4-10 < HLL_8-10 by ~46% in typical use. Matches DataSketches HLL_4-12 = 2095 bytes. Heule et al. 2013 observation: P(rho > 14) is small enough that a few sentinel slots + a hash-table-class exception map is strictly cheaper than 6-bit or 8-bit dense storage at high lgK. For HLL_4-12 at N = 10^9, expected exceptions < 50 entries. Per the lossless-language discipline (doc 20): the typed envelope API is invariant across packing strategies. HLL_4, HLL_6, HLL_8 all return the same ApproxI64 shape; users see memory drop without semantic change.

dependencies 4 imports · 2 importers

syscalls.nx murmur3.nx sketch_hll.nx sketch_types.nx sketch_hll4.nx sketch_hll4_test.nx sketch_hll4_vs_hll8_bench.nx

imports: syscalls.nxmurmur3.nxsketch_hll.nxsketch_types.nx

imported by: sketch_hll4_test.nxsketch_hll4_vs_hll8_bench.nx

structs

40struct Hll4Except {
47struct Hll4 {

consts

28const NX_HLL4_LGK_MIN: i64 = 4
29const NX_HLL4_LGK_MAX: i64 = 10
31const NX_HLL4_SEED_HI: i64 = 0x9747B28C
32const NX_HLL4_SEED_LO: i64 = 0x36185EC0
35const NX_HLL4_SENTINEL: i64 = 15
89const NX_HLL4_EXCEPT_INITIAL_CAP: i64 = 8

functions

65func nx_hll4_get_packed(regs: *u8, idx: i64) -> i64 {
called by 2: nx_hll4_readmain
74func nx_hll4_set_packed(regs: *u8, idx: i64, value: i64) -> i64 {
called by 1: nx_hll4_write
91func nx_hll4_except_find(h: *Hll4, idx: i64) -> i64 {
103func nx_hll4_except_set(h: *Hll4, idx: i64, value: i64) -> i64 {
called by 1: nx_hll4_write calls 1: nx_hll4_except_find
142func nx_hll4_read(h: *Hll4, idx: i64) -> i64 {
156func nx_hll4_write(h: *Hll4, idx: i64, value: i64) -> i64 {
169func nx_hll4_alloc(lg_k: i64, seed: i64) -> *Hll4 {
called by 2: mainmain
194func nx_hll4_add(h: *Hll4, key: *u8, len: i64) -> i64 {
223func nx_hll4_estimate(h: *Hll4) -> i64 {
252func nx_hll4_query(h: *Hll4) -> *ApproxI64 {
263func nx_hll4_memory_bytes(h: *Hll4) -> i64 {
called by 1: main
268func nx_hll4_exception_count(h: *Hll4) -> i64 {
called by 2: mainmain