bloom

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Copyright (c) 2022 Blockwatch Data Inc. Author: alex@blockwatch.cc

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Estimate

func Estimate(n uint64, p float64) (m int, k int)

Estimate returns an estimated bit count and hash count given the element count and false positive rate. TODO: adjust formula to fixed k = 4

func Hash

func Hash(data []byte) [2]uint32

func HashFloat32

func HashFloat32(v float32) [2]uint32

func HashFloat64

func HashFloat64(v float64) [2]uint32

func HashInt16

func HashInt16(v int16) [2]uint32

func HashInt32

func HashInt32(v int32) [2]uint32

func HashInt64

func HashInt64(v int64) [2]uint32

func HashUint16

func HashUint16(v uint16) [2]uint32

func HashUint32

func HashUint32(v uint32) [2]uint32

func HashUint64

func HashUint64(v uint64) [2]uint32

Types

type Filter

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

Filter represents a bloom filter.

func NewFilter

func NewFilter(m int) *Filter

NewFilter returns a new instance of Filter using m bits. If m is not a power of two then it is rounded to the next highest power of 2.

func NewFilterBuffer

func NewFilterBuffer(buf []byte) (*Filter, error)

NewFilterBuffer returns a new instance of a filter using a backing buffer. The buffer length MUST be a power of 2.

func (*Filter) Add

func (f *Filter) Add(v []byte)

Add inserts data to the filter.

func (*Filter) AddMany

func (f *Filter) AddMany(l [][]byte)

AddMany inserts multiple data points to the filter.

func (*Filter) AddManyFloat32

func (f *Filter) AddManyFloat32(data []float32)

AddMany inserts multiple data points to the filter.

func (*Filter) AddManyFloat64

func (f *Filter) AddManyFloat64(data []float64)

AddMany inserts multiple data points to the filter.

func (*Filter) AddManyInt16

func (f *Filter) AddManyInt16(data []int16)

AddMany inserts multiple data points to the filter.

func (*Filter) AddManyInt32

func (f *Filter) AddManyInt32(data []int32)

AddMany inserts multiple data points to the filter.

func (*Filter) AddManyInt64

func (f *Filter) AddManyInt64(data []int64)

AddMany inserts multiple data points to the filter.

func (*Filter) AddManyUint16

func (f *Filter) AddManyUint16(data []uint16)

AddMany inserts multiple data points to the filter.

func (*Filter) AddManyUint32

func (f *Filter) AddManyUint32(data []uint32)

AddMany inserts multiple data points to the filter.

func (*Filter) AddManyUint64

func (f *Filter) AddManyUint64(data []uint64)

AddMany inserts multiple data points to the filter.

func (*Filter) Bytes

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

Bytes returns the underlying backing slice.

func (*Filter) Clone

func (f *Filter) Clone() *Filter

Clone returns a copy of f.

func (*Filter) Contains

func (f *Filter) Contains(v []byte) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) ContainsAnyHash

func (f *Filter) ContainsAnyHash(l [][2]uint32) bool

ContainsAnyHash returns true if the filter contains any hash value in l. Returns false if the filter definitely does not contain any hash in l.

func (*Filter) ContainsFloat32

func (f *Filter) ContainsFloat32(v float32) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) ContainsFloat64

func (f *Filter) ContainsFloat64(v float64) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) ContainsHash

func (f *Filter) ContainsHash(h [2]uint32) bool

ContainsHash returns true if the filter contains hash value h. Returns false if the filter definitely does not contain h.

func (*Filter) ContainsInt16

func (f *Filter) ContainsInt16(v int16) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) ContainsInt32

func (f *Filter) ContainsInt32(v int32) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) ContainsInt64

func (f *Filter) ContainsInt64(v int64) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) ContainsUint16

func (f *Filter) ContainsUint16(v uint16) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) ContainsUint32

func (f *Filter) ContainsUint32(v uint32) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) ContainsUint64

func (f *Filter) ContainsUint64(v uint64) bool

Contains returns true if the filter possibly contains v. Returns false if the filter definitely does not contain v.

func (*Filter) K

func (f *Filter) K() uint32

K returns the number of hash functions used in the filter.

func (*Filter) Len

func (f *Filter) Len() uint

Len returns the number of bits used in the filter.

func (*Filter) Merge

func (f *Filter) Merge(other *Filter) error

Merge performs an in-place union of other into f. Returns an error if m or k of the filters differs.

func (*Filter) Reset

func (f *Filter) Reset()

Reset all bits in the filter.

Jump to

Keyboard shortcuts

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