bloom

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidNumHashes  = errors.New("numHashes must be positive")
	ErrInvalidNumEntries = errors.New("numEntries must be positive")
)

Functions

func Hash

func Hash(b []byte, extra []byte) uint64

Hash computes a 64-bit hash of the given bytes. The extra parameter allows for additional entropy.

func OptimalParameters

func OptimalParameters(maxN int, p float64) (numHashes int, numEntries int)

OptimalParameters returns optimal numHashes and numEntries for a bloom filter given the expected number of elements and desired false positive probability.

Types

type Filter

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

Filter is a thread-safe bloom filter.

func New

func New(numHashes, numEntries int) (*Filter, error)

New creates a new bloom filter with the given parameters.

func (*Filter) Add

func (f *Filter) Add(hash uint64)

Add adds the hash to the filter.

func (*Filter) Contains

func (f *Filter) Contains(hash uint64) bool

Contains checks if the hash might be in the filter.

func (*Filter) MarshalBinary

func (f *Filter) MarshalBinary() ([]byte, error)

MarshalBinary returns the binary representation of the filter.

func (*Filter) UnmarshalBinary

func (f *Filter) UnmarshalBinary(data []byte) error

UnmarshalBinary restores the filter from binary representation.

Jump to

Keyboard shortcuts

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