Documentation ¶
Index ¶
Constants ¶
const ( // DefaultFalsePosProb is the default value (1%) for the probability of a // false positive in a Bloom filter. DefaultFalsePosProb = 0.01 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BloomFilter ¶
type BloomFilter struct {
// contains filtered or unexported fields
}
BloomFilter implements a space-efficient randomized data structure for representing a set in order to support membership queries. The filters allow for false positives, however, the space savings often outweigh this drawback. In other words, the filter allows for one-sided errors: Either an element is "probably" in the set or it is definitely not in the set.
The Fundamental implementation contains two hash functions that allow for a double hashing technique to facilitate up to k-1 hashes. This is combined with the size of the bit vector, directly correlates to the probability of a false positive.
Choice for double hashing was shown to be effective without any loss in the asymptotic false positive probability, leading to less computation and potentially less need for randomness in practice by Adam Kirsch and Michael Mitzenmacher in: 'Less Hashing, Same Performance: Building a Better Bloom Filter'
Non-cryptographic hash functions FNV-1a and MurmurHash3 are used for speed performance.
func NewBloomFilter ¶
func NewBloomFilter(n uint64, p float64) (*BloomFilter, error)
NewBloomFilter returns a reference to a new Bloom filter. It requires a, potentially approximate, set size n and false positive probability p. The optimal value of k, number of hash functions, and m, bit vector size will be used.
func (*BloomFilter) Includes ¶
func (bf *BloomFilter) Includes(data []byte) (bool, error)
Includes returns whether or not some arbitrary set item (byte slice) is most likely in the Bloom filter. There is a possibility for a false positive with the probability being under the Bloom filter's p value. An error is returned if any hash function write fails.
func (*BloomFilter) NumItemsApprox ¶
func (bf *BloomFilter) NumItemsApprox() uint64
NumItemsApprox returns the approximate total number of items in the Bloom filter.
func (*BloomFilter) Set ¶
func (bf *BloomFilter) Set(data []byte) error
Set accepts a set item (byte slice) and sets the appropriate bits to 1 in the bit vector. An error is returned if any hash function write fails. Enhanced double hashing is used with two hash functions instead of k uniform random hash functions.
func (*BloomFilter) String ¶
func (bf *BloomFilter) String() string
String implements the Stringer interface for a Bloom filter.