Documentation ¶
Overview ¶
Package bloomfilter implements bloomfilter data structure.
A Bloom filter is a data structure designed to tell you, rapidly and memory-efficiently, whether an element is present in a set. The price paid for this efficiency is that a Bloom filter is a probabilistic data structure: it tells us that the element either definitely is not in the set or may be in the set.
Example:
package main import ( "hash/fnv" "github.com/darkLord19/bloomfilter" ) func main() { bf := bloomfilter.New(10000, 0.10, fnv.New64()) bf.Add([]byte("A")) bf.Add([]byte("B")) status, err := bf.DoesNotExist([]byte("C")) elems := bf.ElementsEstimate() }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BloomFilter ¶
type BloomFilter struct { Size uint32 BitArray []bool NumberOfHashFunctions uint8 HashFunction hash.Hash64 AcceptableFalsePositiveProbability float64 // contains filtered or unexported fields }
BloomFilter data struct
func New ¶
func New(elements uint32, acceptableFalsePositiveProbability float64, hash hash.Hash64) *BloomFilter
New returns pointer to newly created BloomFilter struct. It accepts three arguments. 1st is number of elements you want to track 2nd is acceptable false positive probability 3rd is the hash function you want to use
func (*BloomFilter) Add ¶
func (b *BloomFilter) Add(element []byte) error
Add inserts new element in bloomfilter instance
func (*BloomFilter) DoesNotExist ¶
func (b *BloomFilter) DoesNotExist(element []byte) (bool, error)
DoesNotExist checks if element does not exist for sure in our dataset
func (*BloomFilter) ElementsEstimate ¶
func (b *BloomFilter) ElementsEstimate() uint32
ElementsEstimate gives approximate number of items in bloom filter