Simple Bloom Filter implementation using murmur3
go get "github.com/vivangkumar/gobloom"
You can use gobloom like this
package main
import (
"github.com/vivangkumar/gobloom"
"fmt"
)
func main() {
bf := gobloom.NewBloomFilter(10, 3)
bf.Add("one", "two")
fmt.Print(bf.Contains("one"))
}
The API (for now) is pretty simple.
-
NewBloomFilter(size, hashFuncs int)
: Returns a reference to a new BloomFilter initialized with thesize
(number of bits) andHashFuncs
(number of times to Hash) -
(bf *BloomFilter) Add(items ...string)
: Add new items to the filter. -
(bf *BloomFilter) Contains(item string) bool
: Returns abool
value depending on existence in the filter. Increasing the size of the filter can reduce false positives. However, this is a pretty basic implementation, so be aware.
Run tests using go test
(Just simple cases, I'll add more later)
This code is licenced under the MIT Licence