bloom

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

README

bloom

Go Reference

The bloom package is a zero-allocation implementation of a Bloom Filter in Go. It uses Go's hash/maphash package to generate hashes for any comparable item with no allocations required.

Documentation

Overview

Package bloom contains a generic bloom filter type that can be used with any comparable value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter[T comparable] struct {
	// contains filtered or unexported fields
}

Filter represents a space-efficient probabilistic data structure that tests whether an element is a member of a set. Once a Filter has been created, adding a new item to the set does not require any additional memory allocation.

func NewBloomFilter

func NewBloomFilter[T comparable](expectedItems uint, falsePositiveRate float64) *Filter[T]

NewBloomFilter creates a new Bloom filter optimized for the expected number of items and desired false positive rate.

func (*Filter[T]) Add

func (bf *Filter[T]) Add(item T)

Add inserts an item into the Bloom filter.

This method is not safe for concurrent use.

func (*Filter[T]) Contains

func (bf *Filter[T]) Contains(item T) bool

Contains tests whether an item might be in the set. False positives are possible, but false negatives are not.

This method can be called concurrently with other calls to itself or Filter.EstimatedFalsePositiveRate, but not Filter.Add.

func (*Filter[T]) EstimatedFalsePositiveRate

func (bf *Filter[T]) EstimatedFalsePositiveRate() float64

EstimatedFalsePositiveRate returns the current estimated false positive rate based on the number of items added.

This method can be called concurrently with other calls to Filter.Contains or itself.

Jump to

Keyboard shortcuts

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