Documentation ¶
Overview ¶
In this implementation, the hashing functions used is murmurhash, a non-cryptographic hashing function.
Index ¶
- func EstimateFalsePositiveRate(m, k, n uint, b BitSet) (fpRate float64)
- func EstimateParameters(n uint, p float64) (m uint, k uint)
- func Locations(data []byte, k uint) []uint64
- type BitSet
- type BloomFilter
- type RedisBitSet
- func (r *RedisBitSet) ClearAll() BitSet
- func (r *RedisBitSet) Count() uint
- func (r *RedisBitSet) Equal(c BitSet) bool
- func (r *RedisBitSet) From(buf []uint64) BitSet
- func (r *RedisBitSet) GetBitSetKey() string
- func (r *RedisBitSet) InPlaceUnion(compare BitSet)
- func (r *RedisBitSet) Init(length uint) BitSet
- func (r *RedisBitSet) ReadFrom(stream io.Reader) (int64, error)
- func (r *RedisBitSet) Set(i uint) BitSet
- func (r *RedisBitSet) Test(i uint) bool
- func (r *RedisBitSet) UnSet(i uint) BitSet
- func (r *RedisBitSet) WriteTo(stream io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstimateFalsePositiveRate ¶
EstimateFalsePositiveRate returns, for a BloomFilter of m bits and k hash functions, an estimation of the false positive rate when
storing n entries. This is an empirical, relatively slow
test using integers as keys. This function is useful to validate the implementation.
func EstimateParameters ¶
EstimateParameters estimates requirements for m and k. Based on https://bitbucket.org/ww/bloom/src/829aa19d01d9/bloom.go used with permission.
Types ¶
type BitSet ¶
type BitSet interface { // Init allocate bit set based on bit length Init(length uint) BitSet // Set bit i to 1, the capacity of the bitset is automatically // increased accordingly. // If i>= Cap(), this function will panic. // Warning: using a very large value for 'i' // may lead to a memory shortage and a panic: the caller is responsible // for providing sensible parameters in line with their memory capacity. Set(i uint) BitSet // UnSet bit i to 0 UnSet(i uint) BitSet // InPlaceUnion creates the destructive union of base set and compare set. // This is the BitSet equivalent of | (or). InPlaceUnion(compare BitSet) // Test whether bit i is set. Test(i uint) bool // ClearAll clears the entire BitSet ClearAll() BitSet // Count (number of set bits). // Also known as "popcount" or "population count". Count() uint // WriteTo writes a BitSet to a stream WriteTo(stream io.Writer) (int64, error) // Equal tests the equivalence of two BitSets. // False if they are of different sizes, otherwise true // only if all the same bits are set Equal(c BitSet) bool // GetBitSetKey returns the key of redis bitset. It is used only for redis bitset GetBitSetKey() string // ReadFrom reads a BitSet from a stream written using WriteTo ReadFrom(stream io.Reader) (int64, error) // From is a constructor used to create a BitSet from an array of integers From(buf []uint64) BitSet }
type BloomFilter ¶
type BloomFilter interface { // Cap returns the capacity, _m_, of a Bloom filter Cap() uint // K returns the number of hash functions used in the BloomFilter K() uint // BitSet returns the underlying bitset for this filter. BitSet() BitSet // Add data to the Bloom Filter. Returns the filter (allows chaining) Add(data []byte) BloomFilter // AddString to the Bloom Filter. Returns the filter (allows chaining) AddString(data string) BloomFilter // Test returns true if the data is in the BloomFilter, false otherwise. // If true, the result might be a false positive. If false, the data // is definitely not in the set. Test(data []byte) bool // TestString returns true if the string is in the BloomFilter, false otherwise. // If true, the result might be a false positive. If false, the data // is definitely not in the set. TestString(data string) bool // TestLocations returns true if all locations are set in the BloomFilter, false // otherwise. TestLocations(locs []uint64) bool // TestAndAdd is the equivalent to calling Test(data) then Add(data). // Returns the result of Test. TestAndAdd(data []byte) bool // TestAndAddString is the equivalent to calling Test(string) then Add(string). // Returns the result of Test. TestAndAddString(data string) bool // TestOrAdd is the equivalent to calling Test(data) then if not present Add(data). // Returns the result of Test. TestOrAdd(data []byte) bool // TestOrAddString is the equivalent to calling Test(string) then if not present Add(string). // Returns the result of Test. TestOrAddString(data string) bool // ClearAll clears all the data in a Bloom filter, removing all keys ClearAll() BloomFilter // ApproximatedSize approximates the number of items // https://en.wikipedia.org/wiki/Bloom_filter#Approximating_the_number_of_items_in_a_Bloom_filter ApproximatedSize() uint32 // MarshalJSON implements json.Marshaler interface. MarshalJSON() ([]byte, error) // UnmarshalJSON implements json.Unmarshaler interface. UnmarshalJSON(data []byte) error // WriteTo writes a binary representation of the BloomFilter to an i/o stream. // It returns the number of bytes written. WriteTo(stream io.Writer) (int64, error) // ReadFrom reads a binary representation of the BloomFilter (such as might // have been written by WriteTo()) from an i/o stream. It returns the number // of bytes read. ReadFrom(stream io.Reader) (int64, error) // GobEncode implements gob.GobEncoder interface. GobEncode() ([]byte, error) // GobDecode implements gob.GobDecoder interface. GobDecode(data []byte) error // Equal tests for the equality of two Bloom filters Equal(g BloomFilter) bool }
func From ¶
func From(data []uint64, k uint, b BitSet) BloomFilter
From creates a new Bloom filter with len(_data_) * 64 bits and _k_ hashing functions. The data slice is not going to be reset.
func FromWithM ¶
func FromWithM(data []uint64, m, k uint, b BitSet) BloomFilter
FromWithM creates a new Bloom filter with _m_ length, _k_ hashing functions. The data slice is not going to be reset.
func New ¶
func New(m uint, k uint, b BitSet) BloomFilter
New creates a new Bloom filter with _m_ bits and _k_ hashing functions We force _m_ and _k_ to be at least one to avoid panics.
func NewWithEstimates ¶
func NewWithEstimates(n uint, fp float64, b BitSet) BloomFilter
NewWithEstimates creates a new Bloom filter for about n items with fp false positive rate
type RedisBitSet ¶
type RedisBitSet struct {
// contains filtered or unexported fields
}
func (*RedisBitSet) ClearAll ¶
func (r *RedisBitSet) ClearAll() BitSet
func (*RedisBitSet) Count ¶
func (r *RedisBitSet) Count() uint
func (*RedisBitSet) Equal ¶
func (r *RedisBitSet) Equal(c BitSet) bool
func (*RedisBitSet) From ¶
func (r *RedisBitSet) From(buf []uint64) BitSet
func (*RedisBitSet) GetBitSetKey ¶
func (r *RedisBitSet) GetBitSetKey() string
func (*RedisBitSet) InPlaceUnion ¶
func (r *RedisBitSet) InPlaceUnion(compare BitSet)
func (*RedisBitSet) Init ¶
func (r *RedisBitSet) Init(length uint) BitSet
func (*RedisBitSet) Set ¶
func (r *RedisBitSet) Set(i uint) BitSet
func (*RedisBitSet) Test ¶
func (r *RedisBitSet) Test(i uint) bool
func (*RedisBitSet) UnSet ¶
func (r *RedisBitSet) UnSet(i uint) BitSet