Skip to content
/ bloom Public

Golang bloom filter implementation - Scalable, Partitionned & Standard filters

License

Notifications You must be signed in to change notification settings

Xide/bloom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bloom

Standard, Scalable & partitionned bloom filter implementations. Maths for this project were coded using this implementation.


Usage

Standard

Basic usage
// Create a new Filter of 512 bytes using 5 different hash functions
bf := bloom.New(512, 5)

// Insert element in the filter
bf.Feed("An item")

// Query for an element membership
bf.Match("An item")
// true

bf.Match("Another item")
// false
Merge filters
bf := bloom.New(512, 5)
oth := bloom.New(512, 5)

bf.Feed("foo")
oth.Feed("bar")

bf.Merge(oth)

bf.Match("foo") && bf.Match("bar")
/// true
Export/Import filter
// Export filter as []byte for exportation
bytes, _ := bf.ToJSON()

// Export directly to filesystem (as json)
err := bf.ToFile("file.json")

Filters can then be imported with :

// Import directly from JSON bytes
bf, err := bloom.FromJSON(bytes)

// Import directly from filesystem (as json)
bf, err := bloom.FromFile("file.json")
Filter fill ratio
// Average ratio of bits set to 1; count each bit of the underlying array
// Might cause slowdown if used too much
bf.FillRatio()

// Optimization of the function above, estimate instead of counting
bf.EstimateFillRatio()

Both functions return a float64 between 0 and 1. Please keep in mind that EstimateFillRatio yield an approximate ratio, if you need precision below ~0.1, consider using directly FillRatio.

Scalable

bf := bloom.NewScalableDefault()

About

Golang bloom filter implementation - Scalable, Partitionned & Standard filters

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages