bloom

package module
v0.0.0-...-b01d291 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 5 Imported by: 0

README

bloom

A set of bloom filter implementations, forked from zentures due to inactivity.

Godoc Reference Go Report Card Go

Package bloom currently supports:

  • Optimized bloom filters (hash-partitioned arrays)
  • Scalable Bloom Filters

Additional information regarding benchmarks is here.

For examples, take a look at the *_test.go files in each of the directories.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

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

Filter is the standard implementation used by this package. It is a variant implementation of the standard bloom filter that reduces the risk of false-positives by assigning a bit array to each hash function.

Reference #2: Scalable Bloom Filters (http://gsd.di.uminho.pt/members/cbm/ps/dpdf)

The name Partitioned Bloom Filter is my choice as there was no name assigned to f variant.

func New

func New(n uint, opt ...Option) *Filter

New initializes a new partitioned bloom filter. n is the number of items f bloom filter predicted to hold.

func (*Filter) Add

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

func (*Filter) Check

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

func (*Filter) Count

func (f *Filter) Count() uint

func (*Filter) EstimatedFillRatio

func (f *Filter) EstimatedFillRatio() float64

func (*Filter) FillRatio

func (f *Filter) FillRatio() float64

func (*Filter) Reset

func (f *Filter) Reset()

type Option

type Option func(*params)

func WithErrorRate

func WithErrorRate(e float64) Option

WithErrorRate sets the desired error rate for the bloom filter. Smaller values of e imply a larger number of hash values used to set and test bits (the K parameter).

If e <= 0, defaults to .001.

func WithFillRatio

func WithFillRatio(p float64) Option

WithFillRation specifies the maximum porportion of bits that may be set to 1 in the filter. This influences how large the filter must be in order to guarantee the specified error rate. Note that this fill ratio is not strictly enforced. Overloading a filter happens silently, causing the error rate (false positives) to increase.

If p <= 0, defaults to 0.5

func WithHash

func WithHash(h hash.Hash) Option

WithHash specifies the hash to use with the bloom filter. If h == nil, defaults to CityHash.

type ScalableFilter

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

ScalableFilter is an implementation of the Scalable Bloom Filter that "addresses the problem of having to choose an a priori maximum size for the set, and allows an arbitrary growth of the set being presented." Reference #2: Scalable Bloom Filters (http://gsd.di.uminho.pt/members/cbm/ps/dbloom.pdf)

func NewScalable

func NewScalable(n uint, opt ...Option) *ScalableFilter

New initializes a new partitioned bloom filter. n is the number of items sbf bloom filter predicted to hold.

func (*ScalableFilter) Add

func (sbf *ScalableFilter) Add(item []byte)

func (*ScalableFilter) Check

func (sbf *ScalableFilter) Check(item []byte) bool

func (*ScalableFilter) Count

func (sbf *ScalableFilter) Count() uint

func (*ScalableFilter) EstimatedFillRatio

func (sbf *ScalableFilter) EstimatedFillRatio() float64

func (*ScalableFilter) FillRatio

func (sbf *ScalableFilter) FillRatio() float64

func (*ScalableFilter) Reset

func (sbf *ScalableFilter) Reset()

Jump to

Keyboard shortcuts

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