bloomfilter

package
v0.0.0-...-19431fd Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 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 struct contains the required parameters to create and use a filter such as the data bitmap (data), the optimal number of bits (m), the optimal number of hash functions (k) and the size of the filter (n). It also contains an instance of the hash function to better performance. Read more about Bloom Filter definition and implementation here: https://en.wikipedia.org/wiki/Bloom_filter.

func NewFilter

func NewFilter(size int, fp float64) (filter *BloomFilter)

NewFilter functions initializes a new BloomFilter with the size and false positive rate provided as argument. Using this arguments, it calculates the optimal number of bits for the number of items to store, and optimal number of hash functions for this size.

func (*BloomFilter) Add

func (f *BloomFilter) Add(items ...[]byte)

Add function allows to user to insert one (or more) items to the created filter. It calculates the position of each input with the number of hashes to mark as contained.

func (*BloomFilter) Test

func (f *BloomFilter) Test(item []byte) bool

Test function allows to user to check if the current filter has already an item provided as input. It performs almost the same action as Add function, but checking if each hashed position is already marked. If some of the positions are not marked, the filter does not contains the provided item.

func (*BloomFilter) TestMultiple

func (f *BloomFilter) TestMultiple(items ...[]byte) (results []bool)

TestMultiple function allows to the user to test multiple inputs at the same time, using the BloomFilter.Test function.

Jump to

Keyboard shortcuts

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