Skip to main content

Module shared_hyper_log_log

Module shared_hyper_log_log 

Source
Expand description

SharedHyperLogLog - cross-process probabilistic distinct-count estimator.

2^p AtomicU8 registers, each storing the maximum-observed rank (leading-zero count + 1) of items hashed to that register. Estimate via harmonic mean with bias correction.

§Why this is safe

Each insert is exactly one fetch_max on one AtomicU8. No CAS loops, no Drop guards, no spin waits. The cache-line contention is bounded to one register per insert.

§Accuracy

Standard error ~= 1.04 / sqrt(m) where m = 2^p.

pmstd errsize
82566.5%256B
1010243.3%1 KB
1240961.6%4 KB
14163840.8%16 KB
16655360.4%64 KB

§Encoding

Hash item to u64 h. Register index = top p bits of h. Rank = (leading_zeros of (h << p) | (1 << (63-p))) + 1, clamped to 64. (The OR ensures rank is bounded even when low bits are 0.)

Structs§

HLLHeader
SharedHyperLogLog

Enums§

HLLError

Constants§

HLL_MAGIC
MAX_PRECISION
Maximum precision (larger = more memory).
MIN_PRECISION
Minimum precision (smaller = less memory but worse accuracy).

Functions§

hll_file_size