Documentation
¶
Overview ¶
Package bloom is a Bloom filter implementation of monoid.Monoid[[]byte], suitable for approximate set-membership aggregations.
Backed by github.com/bits-and-blooms/bloom/v3. Combine is bitwise-OR of the two underlying bit arrays; Identity is an empty bit array of the same size. All sketches in a pipeline must share the same (m, k) parameters — Combine refuses to merge sketches with mismatched shapes (returns the left operand on mismatch).
Default parameters: 1M bits, k=7 hash functions, ~1% false-positive rate at ~100K inserts. Use NewWithCapacity for custom sizing.
Index ¶
- Constants
- func Bloom() monoid.Monoid[[]byte]
- func Contains(sketch, element []byte) bool
- func Equal(a, b []byte) bool
- func Inspect(sketch []byte) (capacity uint64, hashes uint32, approxSize uint64, err error)
- func NewSingle(n uint, p float64, element []byte) []byte
- func NewWithCapacity(n uint, p float64) monoid.Monoid[[]byte]
- func Single(element []byte) []byte
Constants ¶
const ( DefaultCapacity = 100_000 DefaultFPR = 0.01 )
Default capacity and FPR. Yields ~10K-bit filter at p=0.01, k=7.
Variables ¶
This section is empty.
Functions ¶
func Bloom ¶
Bloom returns a Bloom-filter monoid with default parameters. To track a different expected cardinality / FPR, use NewWithCapacity.
func Contains ¶
Contains reports whether element is (probably) in the marshaled filter. Returns false on decode error.
func Equal ¶
Equal reports whether two marshaled filters have identical bits and shape. Used in tests for determinism checks.
func Inspect ¶
Inspect returns the (capacity m, hash count k, approximate number of inserted elements) triple from a marshaled filter. Used by the admin server to render a human-readable view of an opaque sketch in the Query Console.
"Approximate size" comes from the bits-and-blooms library's estimator — derived from the bit-fill ratio against (m, k); accurate within a few percent at typical fill levels, less reliable as the filter approaches saturation.
func NewSingle ¶
NewSingle returns a marshaled Bloom filter sized for (n, p) and pre-populated with the given element. The pipeline's value extractor uses this to lift a per-event element into a one-element sketch suitable for monoidal merge.
func NewWithCapacity ¶
NewWithCapacity returns a Bloom-filter monoid sized for the expected number of distinct elements n and target false-positive rate p. The shape is fixed for the lifetime of the monoid; all sketches it merges must share these parameters.
Types ¶
This section is empty.