Skip to main content

Module union_intersect

Module union_intersect 

Source
Expand description

Set operations on HyperLogLog sketches.

  • estimate_union(a, b) is exact in the HLL sense: merge the two sketches register-wise and estimate. Same operation as the base merge() method, just non-destructive.
  • estimate_intersect(a, b) uses inclusion-exclusion: |A and B| ~= |A| + |B| - |A or B|. This is the only practical HLL intersection. Be aware: when A and B mostly overlap, the variance of the subtraction is large relative to the result, so the estimator gets noisy. The error bound is ~1.04/sqrt(m) * (|A| + |B|), not ~1.04/sqrt(m) * |A and B|. For nearly-disjoint or nearly-identical sets, prefer Apache DataSketches’ Theta sketches.

Functions§

estimate_intersect
Distinct count of the intersection via inclusion-exclusion. Clamps to >= 0 since a negative estimate is a hard signal of large relative error.
estimate_union
Distinct count of the union, exact in the HLL sense.
intersect_error_bound
Absolute error the inclusion-exclusion estimate carries at one standard deviation. It scales with |A| + |B|, so a thin overlap between two large sets can come back with an error bar wider than the answer. Check it against the estimate before believing an intersection.