Documentation ¶
Index ¶
Examples ¶
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 an implementation of a Bloom Filter that permits n concurrent readers and m concurrent writers.
func NewFilter ¶
NewFilter creates a bloom filter optimized for n elements with a falsePositive rate fpRate.
Example ¶
package main import ( "fmt" "github.com/JamesHageman/fastbloom" ) func main() { filter := fastbloom.NewFilter(100, 0.01) fmt.Println(filter.Test([]byte(`a`))) fmt.Println(filter.Test([]byte(`b`))) filter.Add([]byte(`a`)) filter.Add([]byte(`b`)) fmt.Println(filter.Test([]byte(`a`))) fmt.Println(filter.Test([]byte(`b`))) fmt.Println(filter.Test([]byte(`c`))) }
Output: false false true true false
func (*Filter) Add ¶
Add writes a key to the bloom filter. It can be called concurrently with other calls to Add, TestAndAdd, and Test.
func (*Filter) Test ¶
Test tests the filter for the presence of a key. It is (only) guaranteed to return true after a call to Add(key) or TestAndAdd(key) have completed. Because of the possibility of false positives, Test(key) could also return true if the key hasn't been added.
func (*Filter) TestAndAdd ¶
TestAndAdd adds a key to the bloom filter and returns true if it appears that the key was already present.