HyperLogLog and Mergeable Cardinality Estimates

Estimate distinct stream keys from geometric rank observations and merge summaries without counting duplicated items twice.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Rare bit patterns reveal how many distinct hashes arrived
  2. Use several registers to control variability

Rare bit patterns reveal how many distinct hashes arrived

Hash every distinct key approximately uniformly. Use a fixed prefix to select one of \(m\) registers. In the remaining suffix, report the position of the first one, starting at one. Under fair bits, \(\Pr[\rho\ge r]=2^{-(r-1)}\) within the available width. A register retains the maximum rank it has seen. A large maximum is more likely after many distinct samples, while repeated copies of a key give the same hash and leave the maximum unchanged.

Use several registers to control variability

The raw estimator is proportional to \(m^2/\sum_j2^{-M_j}\) with a register-count correction factor. It combines transformed registers rather than averaging raw maxima, which would be sensitive to rare large ranks. Merge compatible summaries by taking the componentwise maximum. This exactly reproduces the register state of the union. Small-range corrections and finite hash width matter for estimates near either extreme. Bloom filters summarize approximate membership. Stream aggregation explains why a merge must preserve a statistic’s meaning under repartitioning.[1]

References

  1. Philippe Flajolet et al., HyperLogLog: The Analysis of a Near-Optimal Cardinality Estimation Algorithm ↩