bloomfilter

package module
v0.0.0-...-1292d07 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 2 Imported by: 0

README

Go Reference

Here is an example implementation of a bloom filter in Golang that includes an add and remove function, and is atomic aware:

To create a BloomFilter instance, call the NewBloomFilter function and pass in the desired size of the filter (the number of bits), as well as an array of hash functions to be used. For example:

filter := bloomfilter.NewBloomFilter(10000, []bloomfilter.HashFunc{bloomfilter.NewHashFunc()})

To add a key to the filter, call the Add method on the filter instance, passing in the key as a string. For example:

filter.Add("A")
filter.Add("B")
filter.Add("C")

To remove a key from the filter, call the Remove method on like below example:

filter.Remove("C")

To check if key exists:

filter.Check("C")

Documentation

Overview

Package bloomfilter implements a simple bloom filter using hashing functions.

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 is a struct representing a bloom filter.

func NewBloomFilter

func NewBloomFilter(size int, funcs []HashFunc) *BloomFilter

NewBloomFilter returns a new bloom filter instance.

The size parameter specifies the size of the in-memory bloom filter array. The funcs parameter is a slice of HashFuncs that will be used to hash inputs to the bloom filter.

func (*BloomFilter) Add

func (b *BloomFilter) Add(key string)

Add adds a new input string to the bloom filter.

func (*BloomFilter) Check

func (b *BloomFilter) Check(key string) bool

Check checks whether an input string is probably in the bloom filter.

func (*BloomFilter) Remove

func (b *BloomFilter) Remove(key string)

Remove removes an input string from the bloom filter

type HashFunc

type HashFunc func(string) uint32

HashFunc is a type representing a hashing function for the bloom filter.

func NewHashFunc

func NewHashFunc() HashFunc

NewHashFunc returns a new FNV-1 hashing function for the bloom filter.

Jump to

Keyboard shortcuts

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