Documentation
¶
Overview ¶
Package bloomfilter implements a bloom-filter for pieces that need to be preserved.
Index ¶
- func GenerateSeed() byte
- func OptimalParameters(expectedElements int64, falsePositiveRate float64, maxSize memory.Size) (hashCount byte, sizeInBytes int)
- type Filter
- func (filter *Filter) Add(pieceID storj.PieceID)
- func (filter *Filter) AddFilter(operand *Filter) error
- func (filter *Filter) Bytes() []byte
- func (filter *Filter) Contains(pieceID storj.PieceID) bool
- func (filter *Filter) FillRate() float64
- func (filter *Filter) Parameters() (hashCount, size int)
- func (filter *Filter) SeedAndParameters() (seed, hashCount byte, size int)
- func (filter *Filter) Size() int64
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.