code wiki / (root) / nx_sketch_histogram.nx

nx_sketch_histogram.nx

buildroot/runtime/nx_sketch_histogram.nx

7439 B217 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind sketch/demotopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_histogram.nx -- fixed-bin histogram with quantile + merge. Linear-bin histogram over a CALLER-DECLARED range [min, max). Each of N buckets holds an exact count. Out-of-range values land in under_count or over_count. COMPLEMENTS the quantile sketches: - sketch_kll: provable uniform rank-error; small footprint - sketch_tdigest: tail-tight; small footprint - sketch_histogram: EXACT bucket counts within declared range; memory = N * 8 bytes (no compression) Caller picks: histogram for known bounded ranges with audit-grade counts, sketches for unbounded streams with bounded error. USE CASES: - HTTP status code distribution (range [200, 600), 1 bucket per code) - Latency distribution with known SLA (range [0, 1000ms)) - Score distribution (range [0, 100)) MERGE: count-wise addition across matched ranges. Refused if ranges differ. LOSSLESS-LANGUAGE DISCIPLINE: nx_hist_query_count(value): NX_ENV_ABS with param_a = 0 if in-range, meaning exact count. For out-of-range we report the under/over counts honestly. nx_hist_query_quantile(p): NX_ENV_RANK_ERROR with param_a = bucket resolution = (max - min) / N expressed in ppb relative to range. MaturityClass = Production (exact within budget).

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_sketch_types.nx nx_sketch_histogram.nx

imports: nx_syscalls.nxnx_sketch_types.nx

imported by: nobody (leaf or entry point)

structs

43struct Histogram

consts

40const NX_HIST_BUCKETS_MIN: i64 = 2
41const NX_HIST_BUCKETS_MAX: i64 = 100000

functions

56func nx_hist_alloc(min_val: i64, max_val: i64, n_buckets: i64) -> *Histogram
called by 1: nx_hist_merge calls 1: sys_mmap
85func nx_hist_bucket(h: *Histogram, value: i64) -> i64
93func nx_hist_add(h: *Histogram, value: i64) -> i64
calls 1: nx_hist_bucket
108func nx_hist_add_n(h: *Histogram, value: i64, count: i64) -> i64
calls 1: nx_hist_bucket
126func nx_hist_count_at(h: *Histogram, idx: i64) -> i64
133func nx_hist_count_for_value(h: *Histogram, value: i64) -> i64
141func nx_hist_quantile(h: *Histogram, p_milli: i64) -> i64
162func nx_hist_query_count_for_value(h: *Histogram, value: i64) -> *ApproxI64
171func nx_hist_quantile_resolution_ppb(h: *Histogram) -> i64
175func nx_hist_query_quantile(h: *Histogram, p_milli: i64) -> *ApproxI64
189func nx_hist_merge(a: *Histogram, b: *Histogram) -> *Histogram
calls 1: nx_hist_alloc
207func nx_hist_total(h: *Histogram) -> i64
211func nx_hist_in_range(h: *Histogram) -> i64
215func nx_hist_memory_bytes(h: *Histogram) -> i64