Documentation ¶
Index ¶
- func Decode(encodedString string) string
- func Encode(inputString string) string
- type Bitset
- type BloomFilter
- type SimpleBloomFilter
- func (bf *SimpleBloomFilter) AddKey(key []byte) (bool, []uint)
- func (bf *SimpleBloomFilter) Compare(remote interface{}) bool
- func (bf *SimpleBloomFilter) GetMaxSize() uint
- func (bf *SimpleBloomFilter) GetStorage() Bitset
- func (bf *SimpleBloomFilter) HasKey(key []byte) (bool, []uint)
- func (bf *SimpleBloomFilter) HashKey(key []byte) []uint
- func (bf *SimpleBloomFilter) Serialize() string
- type WFBitset
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode essentially works opposite of Encode and turns and encoded string into a normal, usable string.
func Encode ¶
Encode handles encoding the bloom filter. An example string before encoding: "AAAABBCCCDZZZRTTT" An example string after encoding "A4B2C3D1Z3R1T3". Please note: This could essentially return an inoptimal compression, as if we have a string with alternating single values (i.e., "01010101010101") this RLE encoding will result in a string twice as long. There is an optimization where we only count runs and not single characters, but for the time being, I don't think it's necessary.
Types ¶
type BloomFilter ¶
type SimpleBloomFilter ¶
type SimpleBloomFilter struct { // Total number of hashing functions HashFunctions uint HashCache *lru.LRUCacheInt32Array // contains filtered or unexported fields }
func Deserialize ¶
func Deserialize(inputString string, maxSize uint) (*SimpleBloomFilter, error)
ConvertStringToBF Decodes the RLE'd bloom filter and then converts it to an actual bloom filter in-memory.
func NewByFailRate ¶
func NewByFailRate(items uint, probability float64) *SimpleBloomFilter
NewByFailRate allows generation of a bloom filter with a pre-conceived amount of items and a false-positive failure rate. We calculate our bloom filter bounds and generate the new bloom filter this way.
func NewSimpleBF ¶
func NewSimpleBF(maxSize uint, hashFuns uint) *SimpleBloomFilter
New Returns a pointer to a newly allocated `SimpleBloomFilter` object
func (*SimpleBloomFilter) AddKey ¶
func (bf *SimpleBloomFilter) AddKey(key []byte) (bool, []uint)
AddKey Adds a new key to the bloom filter
func (*SimpleBloomFilter) Compare ¶
func (bf *SimpleBloomFilter) Compare(remote interface{}) bool
Compare returns if the two bloomfilters are equal
func (*SimpleBloomFilter) GetMaxSize ¶
func (bf *SimpleBloomFilter) GetMaxSize() uint
GetMaxSize returns the max size. Just an ugly getter.
func (*SimpleBloomFilter) GetStorage ¶
func (bf *SimpleBloomFilter) GetStorage() Bitset
GetStorage handles returning the underlying bloomfilter bitset.
func (*SimpleBloomFilter) HasKey ¶
func (bf *SimpleBloomFilter) HasKey(key []byte) (bool, []uint)
HasKey verifies if a key is or isn't in the bloom filter.
func (*SimpleBloomFilter) HashKey ¶
func (bf *SimpleBloomFilter) HashKey(key []byte) []uint
HashKey Takes a string in as an argument and hashes it several times to create usable indexes for the bloom filter.
func (*SimpleBloomFilter) Serialize ¶
func (bf *SimpleBloomFilter) Serialize() string
ConvertToString handles conversion of a bloom filter to a string. Moreover, it enforces RLE encoding, so that fewer bytes are transferred per request.
type WFBitset ¶
type WFBitset struct {
// contains filtered or unexported fields
}
WFBitset is a simple wrapper around the willf bitset library.
func NewWFBitset ¶
NewWFBitset constructs a new bitset to be used with bloom filters.
func (*WFBitset) FromString ¶
FromString handles converting a (valid json) string to a valid underlying bitset.