AlgoViz

HyperLogLog registers and uncertainty

medium 4 min

Split a uniform hash into a register address and remaining bits.

Video lesson · Chapter 1 of 5

One visitor returns through another device signal

0:00 / 3:54

What a run of zeros tells us about visitors

1:25Reel

Theory

Read or listen first. About 1 min.

What it is

HyperLogLog splits a hash into an address and a suffix. The address selects a small register. The length of the initial zero run in the suffix determines the observed rank.

Decode one device hash

0100101AddressSuffix · rank 3Register 10max = 3First visit · max(0, 3) becomes 3.
The first two bits, 01, select register 1. The suffix 00101 starts with two zeros, so its rank is 3. The register rises from 0 to 3.

Why it exists

Seeing an identity again repeats the same observation. New identities occasionally produce unusually large ranks, which let an estimator infer cardinality using bounded memory.

Words to know

Rank
The number of leading zeros in the hash suffix plus one, within the available hash width.

How it works

Step through the idea, or press Play.

Step 1 of 3

Hash a device. Use part of the hash to select a register.

Understand it

Worked example

HyperLogLog registers and uncertainty in practice

Seeing a device repeatedly gives the same hash and cannot keep increasing its register. Many distinct devices spread over registers and occasionally produce larger ranks.

Related case

Three questions for a tiny memory budget

A telemetry service needs to skip pointless disk reads, estimate traffic for a known endpoint, and count unique devices across regions. Each question allows a different error.

One device crosses regions
A device visits two regionsDevice 9first visitRegion AemptyRegion BemptyCount distinct devices across regions

Estimate the union of observed identities.

Sources