bloom

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package bloom implements a Bloom filter, a space-efficient probabilistic data structure used to test whether an element is a member of a set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

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

Filter represents a Bloom filter.

func NewFilter

func NewFilter(n int, p float64, hf Hasher) *Filter

NewFilter creates a new Bloom filter optimized for n items with a false positive probability p using the provided hash function.

func (*Filter) Has

func (f *Filter) Has(v string) bool

Has tests if an element might be in the set.

func (*Filter) ReadFrom

func (f *Filter) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom implements io.ReaderFrom.

func (*Filter) Set

func (f *Filter) Set(v string)

Set adds an element to the Bloom filter.

func (Filter) WriteTo

func (f Filter) WriteTo(w io.Writer) (n int64, err error)

WriteTo implements io.WriterTo.

type HashFunc

type HashFunc func(b []byte) uint64

HashFunc is a function type that implements the Hasher interface.

func (HashFunc) Hash

func (hf HashFunc) Hash(b []byte) uint64

Hash implements the Hasher interface for HashFunc.

type Hasher

type Hasher interface {
	Hash(b []byte) uint64
}

Hasher defines an interface for hash functions that produce uint64 values.

Jump to

Keyboard shortcuts

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