bloom

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

View Source
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

func Bloom() monoid.Monoid[[]byte]

Bloom returns a Bloom-filter monoid with default parameters. To track a different expected cardinality / FPR, use NewWithCapacity.

func Contains

func Contains(sketch, element []byte) bool

Contains reports whether element is (probably) in the marshaled filter. Returns false on decode error.

func Equal

func Equal(a, b []byte) bool

Equal reports whether two marshaled filters have identical bits and shape. Used in tests for determinism checks.

func Inspect

func Inspect(sketch []byte) (capacity uint64, hashes uint32, approxSize uint64, err error)

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

func NewSingle(n uint, p float64, element []byte) []byte

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

func NewWithCapacity(n uint, p float64) monoid.Monoid[[]byte]

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.

func Single

func Single(element []byte) []byte

Single returns the marshaled Bloom filter containing exactly element, sized with the default capacity. Use NewSingle for non-default sizing.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL