code wiki / (root) / sketch_histogram.nx

sketch_histogram.nx

buildroot/runtime/sketch_histogram.nx

7393 B211 linesdepth 4pulls 4 transitivereach 1 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 · 1 importers

syscalls.nx sketch_types.nx sketch_histogram.nx sketch_histogram_test.nx

imports: syscalls.nxsketch_types.nx

imported by: sketch_histogram_test.nx

structs

37struct Histogram {

consts

34const NX_HIST_BUCKETS_MIN: i64 = 2
35const NX_HIST_BUCKETS_MAX: i64 = 100000

functions

50func nx_hist_alloc(min_val: i64, max_val: i64, n_buckets: i64) -> *Histogram {
called by 2: nx_hist_mergemain
79func nx_hist_bucket(h: *Histogram, value: i64) -> i64 {
87func nx_hist_add(h: *Histogram, value: i64) -> i64 {
called by 1: main calls 1: nx_hist_bucket
102func nx_hist_add_n(h: *Histogram, value: i64, count: i64) -> i64 {
called by 1: main calls 1: nx_hist_bucket
120func nx_hist_count_at(h: *Histogram, idx: i64) -> i64 {
called by 1: main
127func nx_hist_count_for_value(h: *Histogram, value: i64) -> i64 {
135func nx_hist_quantile(h: *Histogram, p_milli: i64) -> i64 {
156func nx_hist_query_count_for_value(h: *Histogram, value: i64) -> *ApproxI64 {
165func nx_hist_quantile_resolution_ppb(h: *Histogram) -> i64 {
169func nx_hist_query_quantile(h: *Histogram, p_milli: i64) -> *ApproxI64 {
183func nx_hist_merge(a: *Histogram, b: *Histogram) -> *Histogram {
called by 1: main calls 1: nx_hist_alloc
201func nx_hist_total(h: *Histogram) -> i64 {
called by 1: main
205func nx_hist_in_range(h: *Histogram) -> i64 {
called by 1: main
209func nx_hist_memory_bytes(h: *Histogram) -> i64 {