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.
| p | m | std err | size |
|---|---|---|---|
| 8 | 256 | 6.5% | 256B |
| 10 | 1024 | 3.3% | 1 KB |
| 12 | 4096 | 1.6% | 4 KB |
| 14 | 16384 | 0.8% | 16 KB |
| 16 | 65536 | 0.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§
Enums§
Constants§
- HLL_
MAGIC - MAX_
PRECISION - Maximum precision (larger = more memory).
- MIN_
PRECISION - Minimum precision (smaller = less memory but worse accuracy).