HyperLogLog
A counter of distinct things that keeps none of them. It answers “how many different?” to within about a percent, using an amount of memory that does not grow with the answer.
Where this is actually used
Redis ships this as a built-in type, and Google, Presto and Elasticsearch all use it. Counting unique visitors with an exact set costs memory proportional to the visitors; HyperLogLog counts them in about 12 KB whether there were ten thousand or ten billion.
The guarantee
- alwaysA register value never decreases.
- boundedThe estimate can miss in either direction, by about one standard error.σ ≈ 1.04/√m
How it works
It stores no items. It keeps the longest run of leading zeros seen in each register, reasons that long runs are rare, and counts distinct values from that.
Flajolet, Fusy, Gandouet & Meunier, AofA 2007
Start hereMultiply the stream length by ten and watch two numbers: the estimate follows the true count up, and the memory figure does not move at all. That is the entire trick.
Readings
Running…