bloom

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bloom is a token bloom filter for full-text pruning: a compact, approximate set of the terms present in a column block (e.g. every token across a log part's bodies). A query token that tests **absent** is definitely not in the block, so the reader skips the whole block; a token that tests present may be a false positive, so the engine re-checks the exact predicate per row. The filter never reports a false negative — a token that was [Filter.Add]ed always [Filter.Test]s present — which is what makes block-skipping safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tokenize

func Tokenize(dst [][]byte, s []byte) [][]byte

Tokenize splits s into lowercased tokens — maximal runs of ASCII letters/digits — appending each to dst and returning the extended slice. Non-alphanumeric bytes are separators. Each token is a freshly allocated, lowercased copy (it does not alias s). It is the tokenization used both to fill a body bloom at flush and to derive a query's required tokens, so the two agree.

Types

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter is a bit-array bloom filter with k hash probes derived from one 128-bit hash by double-hashing (Kirsch–Mitzenmacher). The zero value is not usable; build one with New.

func Decode

func Decode(src []byte) (*Filter, int, error)

Decode parses a filter encoded by Filter.Encode, returning it and the number of bytes consumed. It is fully bounds-checked and verifies the trailing CRC.

func New

func New(n int, p float64) *Filter

New returns a filter sized for n expected items at false-positive rate p (0 < p < 1), using the standard m = -n·ln p / (ln2)² and k = (m/n)·ln2, with m rounded up to a multiple of 64 and both m and k clamped to at least their minimums.

func (*Filter) Add

func (f *Filter) Add(item []byte)

Add records item in the filter.

func (*Filter) Encode

func (f *Filter) Encode(dst []byte) []byte

Encode appends the filter's self-describing wire form to dst: [version][uvarint k][uvarint m][bits little-endian]…[u32 CRC32C of the preceding bytes].

func (*Filter) Test

func (f *Filter) Test(item []byte) bool

Test reports whether item may be present: true if every probe bit is set (possibly a false positive), false if any is clear (definitely absent — no false negatives).

Jump to

Keyboard shortcuts

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