bloomzinho

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

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 3 Imported by: 0

README

Bloomzinho

A very simple bloom filter

  • Small and simple code
  • Concurrency-safe lookups (insertions needs to be synchronized)
  • No allocations on lookups, insertions or intersection tests
  • No external dependencies, only standard library
  • Kinda fast
  • Made in Brazil

TODO

  • Better documentation
  • "Contains" method

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
}

func NewFilter

func NewFilter(bits, hashes int) (*Filter, error)

NewFilter creates a new filter if the number of bits is not a multiple of 64 it's rounded up to the next multiple of 64 the number of bits and hashes must be 1 or higher, otherwise an error is returned

func NewIntersection

func NewIntersection(a, b *Filter) (*Filter, error)

func NewUnion

func NewUnion(a, b *Filter) (*Filter, error)

func (*Filter) AddBytes

func (f *Filter) AddBytes(b []byte)

AddBytes is equivalent to AddString but is better when the data is already a []byte

func (*Filter) AddString

func (f *Filter) AddString(s string)

AddString adds a string to the filter

func (*Filter) Intersects

func (f *Filter) Intersects(b *Filter) bool

Intersects tests if the filter intersects with another given filter "b" 2 filters intersecting means that a value that was added to one filter was probably also added to the other

this function is useful if you have a set of values that you want to test against a many filters it is more efficient to make a new filter, add this set and test for intersection than to do multiple lookups when the filters are used this way, it's better to use just one hash

if the 2 filters being tested have different size or number of hashes, this method gives a false positive

func (*Filter) LookupBytes

func (f *Filter) LookupBytes(b []byte) bool

LookupBytes is equivalent to LookupString but is better when the data is already a []byte

func (*Filter) LookupString

func (f *Filter) LookupString(s string) bool

LookupString check if the given string was added to the filter it returns true when the string was probably added if may give a false positive, but never a false negative

Jump to

Keyboard shortcuts

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