Expand description
HyperLogLog cardinality estimator.
Precision p in [4, 18]. The register array is m = 2^p bytes. Hashes
split into a p-bit register index (top bits) and a leading-zero count on
the remaining bits. Each register stores the max observed count + 1.
Estimate is the harmonic mean of 2^r over the registers, scaled by an
alpha_m correction. Linear-counting kicks in at low cardinality where
the raw estimator is biased.
use subms_hyperloglog::HyperLogLog;
let mut hll = HyperLogLog::new(14);
for i in 0..10_000 { hll.add(&format!("key{i}")); }
let est = hll.estimate();
assert!(est > 9_000.0 && est < 11_000.0, "10k distinct within 10%, got {est}");