bloom

package
v0.0.0-...-179e7f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomFilter

type BloomFilter struct {
	// contains filtered or unexported fields
}

BloomFilter https://en.wikipedia.org/wiki/Bloom_filter

func New

func New(n, p int) *BloomFilter

New creates a new Bloom Filter. n is number of elements you want to store and p is false-positive probability.

When you store data on m bits array, the probability of collision is 1/m, so not-collision is 1 - (1/m).

When you use k hash functions and store n elements, the probalibity of not collision is:

(1 - (1/m))^(k*n)

In this case, when you inject non-mebers elements, the probalitity of all bit becames 1 is:

(1 - (1 - (1/m))^(k*n) )^k = (1 - e^(-kn/m))^k

For a given m and n, the value of the number of hash functions k that minimizes the false positive probability is,

k = (m/n)ln(2)

The required number of bits m, the number of inserted elements and a desired false positive probability p (and assuming the optimal value of k is used) can be)

m =  n * log2(e) * log2(1/p)

func (*BloomFilter) Add

func (f *BloomFilter) Add(data []byte) error

Add adds data to the filter.

func (*BloomFilter) Contains

func (f *BloomFilter) Contains(data []byte) bool

Contains returns the given data is added or not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL