inbloom
--
import "github.com/EverythingMe/inbloom/go/inbloom"
Package inbloom implements a portable bloom filter that can export and import
data to and from implementations of the same library in different languages.
Installation
go get github.com/EverythingMe/inbloom/go/inbloom
Usage
type BloomFilter
type BloomFilter struct {
}
BloomFilter is our implementation of a simple dynamically sized bloom filter.
This code was adapted to Go from the libbloom C library -
https://github.com/jvirkki/libbloom
func NewFilter
func NewFilter(entries int, errorRate float64) (*BloomFilter, error)
NewFilter creates an empty bloom filter, with the given expected number of
entries, and desired error rate. The number of hash functions and size of the
filter are calculated from these 2 parameters
func Unmarshal
func Unmarshal(data []byte) (*BloomFilter, error)
Unmarshal reads a binary dump of an inbloom filter with its header, and returns
the resulting filter. Since this is a dump containing size and precisin
metadata, you do not need to specify them.
If the data is corrupt or the buffer is not complete, we return an error
func UnmarshalBase64
func UnmarshalBase64(b64 string) (*BloomFilter, error)
UnmarshalBase64 is a convenience function that unmarshals a filter that has been
encoded into a url parameter
func (*BloomFilter) Add
func (f *BloomFilter) Add(key string) bool
Add adds a key to the filter
func (*BloomFilter) Contains
func (f *BloomFilter) Contains(key string) bool
Contains returns true if a key exists in the filter
func (*BloomFilter) Len
func (f *BloomFilter) Len() int
Len returns the number of BYTES in the filter
func (*BloomFilter) Marshal
func (f *BloomFilter) Marshal() []byte
Marshal dumps the filter to a byte array, with a header containing the error
rate, cardinality and a checksum. This data can be passed to another inbloom
filter over the network, and thus the other end can open the data without the
user having to pass the filter size explicitly. See Unmarshal for reading these
dumpss
func (*BloomFilter) MarshalBase64
func (f *BloomFilter) MarshalBase64() string
MarshalBase64 is a convenience method that dumps the filter's data to a base64
encoded string, ready to be passed as an GET/POST parameter