Documentation
¶
Overview ¶
Package bloomfilter provides a space efficient data structure called a bloom filter. It's main advantage is that it is space efficient compared to structures like hash tables or basic arrays. The downside however is that it can result in false positives,/ though false negatives are not possible. It's time complexity is dependent on/ the number of hash functions used.
Index ¶
- func ToBytes(x interface{}) []byte
- type BitSet
- type BloomFilter
- func (self *BloomFilter) Add(member []byte)
- func (self *BloomFilter) CalculateK() float64
- func (self *BloomFilter) CalculateM() float64
- func (self *BloomFilter) CalculateP() float64
- func (self *BloomFilter) Clear()
- func (self *BloomFilter) Has(member []byte) bool
- func (self *BloomFilter) K() uint
- func (self *BloomFilter) M() uint
- func (self *BloomFilter) P() float64
- func (self *BloomFilter) SetK(k uint)
- func (self *BloomFilter) SetM(m uint)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BitSet ¶
type BitSet []uint8
BitSet is an array of 8-bit integers.
type BloomFilter ¶
BloomFilter represents a basic bloom filter.
func NewBloomFilter ¶
func NewBloomFilter(n int, p float64) *BloomFilter
NewBloomFilter returns an empty bloom filter. It chooses the optimum number of hash functions, k, and bits, m, to be used based on the given expected number of elements, n, and the acceptable false positive rate.
func (*BloomFilter) CalculateK ¶
func (self *BloomFilter) CalculateK() float64
CalculateK returns the number of hashes required in order to satisfy the false positive rate.
func (*BloomFilter) CalculateM ¶
func (self *BloomFilter) CalculateM() float64
CalculateM returns the number of bits required in order to satisfy the false positive rate.
func (*BloomFilter) CalculateP ¶
func (self *BloomFilter) CalculateP() float64
CalculateP returns the expected false positive rate based on the number of hash functions and the size of the bitset.
func (*BloomFilter) Clear ¶
func (self *BloomFilter) Clear()
Clear generates and sets a new empty bitset.
func (*BloomFilter) Has ¶
func (self *BloomFilter) Has(member []byte) bool
Has returns true if the member exists in the set.
func (*BloomFilter) K ¶
func (self *BloomFilter) K() uint
K returns the number of hash functions to be used in each operation.
func (*BloomFilter) SetK ¶
func (self *BloomFilter) SetK(k uint)
SetK can be used to manually set the number of hash functions. This will empty out the set, so use this before inserting any items.
func (*BloomFilter) SetM ¶
func (self *BloomFilter) SetM(m uint)
SetM can be used to manually set the number of bits. This will empty out the set, so use this before inserting any items.