bloom

package
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bloom provides a bloom filter.

Index

Constants

View Source
const (
	// Version is the version number of the binary serialization format. All
	// prior versions up to and including this one are deserializable by this
	// package.
	Version = 1
)

Variables

View Source
var ErrIncompatibleVersion = errors.New("bloom: incompatible version")

Functions

func Len

func Len(n int, p float64) int

Len returns the length of the buffer required to serialize a bloom filter suitable for storing n items with a false positive rate of p.

Types

type Bloom

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

Bloom is a bloom filter which can be used to probabilisticly test whether an item is a member of a set. False positives are possible but false negatives are not. Items may be added but cannot be removed from the set.

func New

func New(n int, p float64) Bloom

New creates a new bloom filter suitable for storing n items with a false positive rate of p.

func NewBits

func NewBits(m int, k uint8) Bloom

NewBits creates a new bloom filter with m bits and k hash functions.

func WithBytes

func WithBytes(buf []byte) (Bloom, error)

WithBytes creates a new bloom filter that uses buf as its backing storage, preserving any existing data in the byte slice. Any subsequent writes to the bloom filter will mutate buf. The layout of the byte buffer must match the layout used by the WriteTo method.

func (*Bloom) Add

func (b *Bloom) Add(v []byte)

Add adds v to the bloom filter.

func (*Bloom) Count

func (b *Bloom) Count() int64

Count returns an estimate of the number of items that have been added to the bloom filter.

func (*Bloom) ErrorRate

func (b *Bloom) ErrorRate() float64

ErrorRate returns an estimate of the rate of false positives returned by the bloom filter's Has method.

func (*Bloom) Has

func (b *Bloom) Has(v []byte) bool

Has reports whether v is possibly present in the bloom filter. If false then the item is definitely not in the set.

func (*Bloom) Len

func (b *Bloom) Len() int

Len returns the length of the buffer required to serialize the bloom filter.

func (*Bloom) ReadFrom

func (b *Bloom) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads a binary representation of the bloom filter from r overwriting any previous configuration. It adheres to the io.ReaderFrom interface protocol. It reads data from r until EOF or error. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned.

func (*Bloom) Reset

func (b *Bloom) Reset()

Reset reverts the bloom filter to a zero count without reallocating the backing buffer.

func (*Bloom) WriteTo

func (b *Bloom) WriteTo(w io.Writer) (int64, error)

WriteTo writes a binary representation of the bloom filter to w. It adheres to the io.WriterTo interface protocol. The return value is the number of bytes written. Any error encountered during the write is also returned.

Source Files

Jump to

Keyboard shortcuts

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