Documentation ¶
Index ¶
Constants ¶
const (
MaxInt = 1<<(intSize-1) - 1
)
Integer limit values.
Variables ¶
var ( // ErrArguments returns by BloomFilter interface. ErrArguments = errors.New("bad arguments") // ErrType returns by BloomFilter interface. ErrType = errors.New("bad type") )
Functions ¶
func OptimalNumOfBitsAndNumOfHashFunctions ¶
func OptimalNumOfBitsAndNumOfHashFunctions( expectInsertions int64, probabilityOfFalsePositives float64) (int64, int, error)
OptimalNumOfBitsAndNumOfHashFunctions gets the best number of bits and the number of hash functions.
It uses
k = m / n * ln(2);
which k is false positive probability, m is the number of bits and n is the expected insertions. See more detail at: https://en.wikipedia.org/wiki/Bloom_filter#Probability_of_false_positives
Types ¶
type BitSet ¶
type BitSet interface { // Set sets those index to true. Set(context.Context, []uint64) error // Get returns true when all indexes are true. Get(context.Context, []uint64) (bool, error) }
BitSet contains a vector of bits that grows as need. Each component of the bit set contains a bool value.
type BloomFilter ¶
type BloomFilter interface { // Add adds an member to set. Add(context.Context, []byte) error // MayExists test whether the element is in the set. // False positive matches are possible MayExists(context.Context, []byte) (bool, error) }
BloomFilter is a space-efficient probabilistic data structure that is used to test whether an element is a member of set.
type DefaultStrategy ¶
type DefaultStrategy struct{}
DefaultStrategy uses double-hashing to generate a sequence of hash value rapidly.
type MemoryBitSet ¶
type MemoryBitSet struct {
// contains filtered or unexported fields
}
MemoryBitSet implements BitSet interface that stores values in memory.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option for creating a BloomFilter.
func WithStrategy ¶
WithStrategy changes the default strategy with custom strategy.
type RedisBitField ¶
type RedisBitField interface {
BitField(ctx context.Context, key string, args ...interface{}) ([]int64, error)
}
RedisBitField is a client that could executing redis bitfield command.
type RedisBitSet ¶
type RedisBitSet struct {
// contains filtered or unexported fields
}
RedisBitSet uses a redis BitField client to implements BitSet interface.
func NewRedisBitSet ¶
func NewRedisBitSet(r RedisBitField, key string) *RedisBitSet
NewRedisBitSet creates a RedisBitSet uses specific redis `key`.