Documentation
¶
Overview ¶
Package bloomfilter is a thread-safe probabilisic filter. With default configuration it can store up to one million elements. All negative results to queries are meant to be 100% accurate, while false positives should happen less than once every three million queries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Elements = 1000000 // n
Elements is the MAX number of elements to store in the filter.
View Source
var NumOfHashes = 5 // k
NumOfHashes is the number of hash functions to use.
Functions ¶
Types ¶
type BloomFilter ¶
BloomFilter is the thread-safe golang version of a bloom filter.
func (*BloomFilter) Add ¶
func (f *BloomFilter) Add(s string)
Add adds an element to a *BloomFilter.
Example ¶
package main import ( "fmt" "github.com/axamon/bloomfilter" ) func main() { f := bloomfilter.New() fmt.Println(f.Exists("pluto")) f.Add("pluto") fmt.Println(f.Exists("pluto")) }
Output: false true
func (*BloomFilter) Exists ¶
func (f *BloomFilter) Exists(s string) bool
Exists returns true false with 100% certainty if element is NOT in the filter, returns true with LESS than 100% certainty if element seems to be present.
Example ¶
package main import ( "fmt" "sync" randomdata "github.com/Pallinder/go-randomdata" "github.com/axamon/bloomfilter" ) func main() { f := bloomfilter.New() n := 10000 var wg sync.WaitGroup wg.Add(n) for i := 0; i < n; i++ { go func() { defer wg.Done() f.Add(randomdata.FirstName(randomdata.Male)) f.Add(randomdata.FirstName(randomdata.Female)) }() } wg.Wait() f.Add("pluto") f.Add("pippo") fmt.Println(f.Exists("pippo")) fmt.Println(f.Exists("pluto")) fmt.Println(f.Exists("minnie")) fmt.Println(f.Exists("paperino")) }
Output: true true false false
Click to show internal directories.
Click to hide internal directories.