nx_sketch_histogram.nx
buildroot/runtime/nx_sketch_histogram.nx
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
imports: nx_syscalls.nxnx_sketch_types.nx
imported by: nobody (leaf or entry point)
structs
| 43 | struct Histogram |
consts
| 40 | const NX_HIST_BUCKETS_MIN: i64 = 2 |
| 41 | const NX_HIST_BUCKETS_MAX: i64 = 100000 |
functions
| 56 | func nx_hist_alloc(min_val: i64, max_val: i64, n_buckets: i64) -> *Histogram |
| 85 | func nx_hist_bucket(h: *Histogram, value: i64) -> i64 |
| 93 | func nx_hist_add(h: *Histogram, value: i64) -> i64 calls 1: nx_hist_bucket |
| 108 | func nx_hist_add_n(h: *Histogram, value: i64, count: i64) -> i64 calls 1: nx_hist_bucket |
| 126 | func nx_hist_count_at(h: *Histogram, idx: i64) -> i64 |
| 133 | func nx_hist_count_for_value(h: *Histogram, value: i64) -> i64 |
| 141 | func nx_hist_quantile(h: *Histogram, p_milli: i64) -> i64 called by 1: nx_hist_query_quantile |
| 162 | func nx_hist_query_count_for_value(h: *Histogram, value: i64) -> *ApproxI64 |
| 171 | func nx_hist_quantile_resolution_ppb(h: *Histogram) -> i64 called by 1: nx_hist_query_quantile |
| 175 | func nx_hist_query_quantile(h: *Histogram, p_milli: i64) -> *ApproxI64 |
| 189 | func nx_hist_merge(a: *Histogram, b: *Histogram) -> *Histogram calls 1: nx_hist_alloc |
| 207 | func nx_hist_total(h: *Histogram) -> i64 |
| 211 | func nx_hist_in_range(h: *Histogram) -> i64 |
| 215 | func nx_hist_memory_bytes(h: *Histogram) -> i64 |