bloomfilter

package
v1.114.4 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: AGPL-3.0 Imports: 8 Imported by: 2

Documentation

Overview

Package bloomfilter implements a bloom-filter for pieces that need to be preserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSeed

func GenerateSeed() byte

GenerateSeed returns a pseudo-random seed between 0 and 254.

func OptimalParameters

func OptimalParameters(expectedElements int64, falsePositiveRate float64, maxSize memory.Size) (hashCount byte, sizeInBytes int)

OptimalParameters returns the optimal parameters for the given expected number of elements, desired false positive rate, and optional maximum memory size.

Types

type Filter

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

Filter is a bloom filter implementation.

func NewExplicit

func NewExplicit(seed, hashCount byte, sizeInBytes int) *Filter

NewExplicit returns a new filter with the explicit seed and parameters.

func NewFromBytes

func NewFromBytes(data []byte) (*Filter, error)

NewFromBytes decodes the filter from a sequence of bytes.

Note: data will be referenced inside the table.

func NewOptimal

func NewOptimal(expectedElements int64, falsePositiveRate float64) *Filter

NewOptimal returns a filter based on expected element count and false positive rate.

func NewOptimalMaxSize

func NewOptimalMaxSize(expectedElements int64, falsePositiveRate float64, maxSize memory.Size) *Filter

NewOptimalMaxSize returns a filter based on expected element count and false positive rate, capped at a maximum size in bytes.

func (*Filter) Add

func (filter *Filter) Add(pieceID storj.PieceID)

Add adds an element to the bloom filter.

func (*Filter) AddFilter

func (filter *Filter) AddFilter(operand *Filter) error

AddFilter adds the given filter into the receiver. The filters must have a matching seed and parameters.

func (*Filter) Bytes

func (filter *Filter) Bytes() []byte

Bytes encodes the filter into a sequence of bytes that can be transferred on network.

func (*Filter) Contains

func (filter *Filter) Contains(pieceID storj.PieceID) bool

Contains return true if pieceID may be in the set.

func (*Filter) FillRate

func (filter *Filter) FillRate() float64

FillRate calculates the proportion of bits filled in.

func (*Filter) Parameters

func (filter *Filter) Parameters() (hashCount, size int)

Parameters returns filter parameters.

func (*Filter) SeedAndParameters

func (filter *Filter) SeedAndParameters() (seed, hashCount byte, size int)

SeedAndParameters returns the seed along with the filter parameters.

func (*Filter) Size

func (filter *Filter) Size() int64

Size returns the size of Bytes call.

Jump to

Keyboard shortcuts

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