You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yet another Bloomfilter implementation in Go, compatible with Java's Guava library. This library borrows how Java's Guava libraray implements Bloomfilter hashing strategies to achieve the serialization compatibility.
Installing
First pull the latest version of the library:
go get github.com/OldPanda/bloomfilter
Then import the this library in your code:
import "github.com/OldPanda/bloomfilter"
Usage Examples
Basic Usage
package main
import (
"fmt""github.com/OldPanda/bloomfilter"
)
funcmain() {
// create bloomfilter with expected insertion=500, error rate=0.01bf, _:=bloomfilter.NewBloomFilter(500, 0.01)
// add number 0~199 into bloomfilterfori:=0; i<200; i++ {
bf.Put(i)
}
// check if number 100 and 200 are in bloomfilterfmt.Println(bf.MightContain(100))
fmt.Println(bf.MightContain(200))
}
Serialization
package main
import"github.com/OldPanda/bloomfilter"funcmain() {
// expected insertion=500, error rate=0.01bf, _:=bloomfilter.NewBloomFilter(500, 0.01)
// add 0~199 into bloomfilterfori:=0; i<200; i++ {
bf.Put(i)
}
// serialize bloomfilter to byte arraybytes:=bf.ToBytes()
// handling the bytes ...
}
Deserialization
package main
import (
"fmt""github.com/OldPanda/bloomfilter"
)
funcmain() {
// create bloomfilter from byte arraybf, _:=bloomfilter.FromBytes(bytes)
// check whether number 100 is in bloomfilterfmt.Println(bf.MightContain(100))
}
Benchmark
The benchmark testing runs on element insertion and query separately.