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 basemerge()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
>= 0since 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.