Documentation ¶
Index ¶
- Variables
- type BadgerStore
- type BloomFilter
- func (bf *BloomFilter) Add(key []byte) error
- func (bf *BloomFilter) Capacity() int
- func (bf *BloomFilter) Clear()
- func (bf *BloomFilter) Close() error
- func (bf *BloomFilter) Contains(key []byte) bool
- func (bf *BloomFilter) Count() int
- func (bf *BloomFilter) DB() interface{}
- func (bf *BloomFilter) FilterSize() int
- func (bf *BloomFilter) Get(key []byte) []byte
- func (bf *BloomFilter) Merge(bf2 *BloomFilter) error
- func (bf *BloomFilter) Put(key, val []byte) error
- func (bf *BloomFilter) Stats() BloomFilterStats
- type BloomFilter2
- type BloomFilterStats
- type BloomOptions
- type BoltStore
- type GrowthRate
- type ScalableBloomFilter
- func (sbf *ScalableBloomFilter) Add(key []byte)
- func (sbf *ScalableBloomFilter) Capacity() int
- func (sbf *ScalableBloomFilter) Clear()
- func (sbf *ScalableBloomFilter) Close() error
- func (sbf *ScalableBloomFilter) Contains(key []byte) bool
- func (sbf *ScalableBloomFilter) Count() int
- func (sbf *ScalableBloomFilter) DB() Store
- func (sbf *ScalableBloomFilter) Get(key []byte) []byte
- func (sbf *ScalableBloomFilter) Put(key, val []byte) error
- func (sbf *ScalableBloomFilter) Stats() BloomFilterStats
- func (sbf *ScalableBloomFilter) Top() *BloomFilter
- type Store
Constants ¶
This section is empty.
Variables ¶
var DefaultBloomOptions = BloomOptions{ Path: "bloom.db", Err_rate: 0.001, Capacity: 10000, GrowthRate: 2, Database: nil, }
var ErrKeyNotFound = fmt.Errorf("Key not found")
Functions ¶
This section is empty.
Types ¶
type BadgerStore ¶
type BadgerStore struct {
// contains filtered or unexported fields
}
func NewBadger ¶
func NewBadger(opts ...badger.Options) *BadgerStore
NewBadger instantiates a new BadgerStore.
func (*BadgerStore) Close ¶
func (store *BadgerStore) Close() error
func (*BadgerStore) DB ¶
func (store *BadgerStore) DB() interface{}
func (*BadgerStore) Put ¶
func (store *BadgerStore) Put(key, value []byte) error
type BloomFilter ¶
type BloomFilter struct {
// contains filtered or unexported fields
}
func NewBloom ¶
func NewBloom(opts *BloomOptions) *BloomFilter
NewBloom creates a new bloom filter. err_rate is the desired false error rate. e.g. 0.001 implies 1 false positive in 1000 lookups
capacity is the number of entries intended to be added to the filter
database is the persistent store to attach to the filter. can be nil.
func (*BloomFilter) Add ¶
func (bf *BloomFilter) Add(key []byte) error
Add adds the key to the bloom filter
func (*BloomFilter) Capacity ¶
func (bf *BloomFilter) Capacity() int
Capacity returns the total capacity of the scalable bloom filter
func (*BloomFilter) Clear ¶
func (bf *BloomFilter) Clear()
Clear resets all bits in the bloom filter
func (*BloomFilter) Close ¶
func (bf *BloomFilter) Close() error
Close flushes the file to disk and closes the file handle to the filter
func (*BloomFilter) Contains ¶
func (bf *BloomFilter) Contains(key []byte) bool
Contains checks if the key exists in the bloom filter
func (*BloomFilter) Count ¶
func (bf *BloomFilter) Count() int
Count returns the number of items added to the bloom filter
func (*BloomFilter) DB ¶
func (bf *BloomFilter) DB() interface{}
DB returns the underlying persistent store
func (*BloomFilter) FilterSize ¶
func (bf *BloomFilter) FilterSize() int
FilterSize returns the size of the bloom filter
func (*BloomFilter) Get ¶
func (bf *BloomFilter) Get(key []byte) []byte
Get gets the key from the underlying persistent store
func (*BloomFilter) Merge ¶
func (bf *BloomFilter) Merge(bf2 *BloomFilter) error
Merge merges the filter with another bloom filter. Both filters must have the same capacity and error rate. merging increases the false positive rate of the resulting filter
func (*BloomFilter) Put ¶
func (bf *BloomFilter) Put(key, val []byte) error
Put adds the key to the bloom filter, and also stores it in the persistent store
func (*BloomFilter) Stats ¶
func (bf *BloomFilter) Stats() BloomFilterStats
Stats returns the stats of the bloom filter
type BloomFilter2 ¶
type BloomFilter2 struct {
// contains filtered or unexported fields
}
func NewBloom2 ¶
func NewBloom2(opts *BloomOptions) *BloomFilter2
NewBloom2 creates a new bloom filter in-memory err_rate is the desired false positive rate. e.g. 0.1 error rate implies 1 in 1000
capacity is the number of entries intended to be added to the filter
database is the persistent store to attach to the filter. can be nil.
func (*BloomFilter2) Add ¶
func (bf *BloomFilter2) Add(key, val []byte)
Add adds the key to the bloom filter
func (*BloomFilter2) Capacity ¶
func (bf *BloomFilter2) Capacity() int
Capacity returns the total capacity of the scalable bloom filter
func (*BloomFilter2) Close ¶
func (bf *BloomFilter2) Close() error
Close closes the file handle to the filter and the persistent store (if any)
func (*BloomFilter2) Contains ¶
func (bf *BloomFilter2) Contains(key []byte) bool
Find checks if the key exists in the bloom filter
func (*BloomFilter2) Count ¶
func (bf *BloomFilter2) Count() int
Count returns the number of items added to the bloom filter
func (*BloomFilter2) FilterSize ¶
func (bf *BloomFilter2) FilterSize() int
FilterSize returns the size of the bloom filter
func (*BloomFilter2) Get ¶
func (bf *BloomFilter2) Get(key []byte) []byte
Get Gets the key from the underlying persistent store
type BloomFilterStats ¶
type BloomOptions ¶
type BloomOptions struct { // path to the filter Path string // The desired false positive rate Err_rate float64 // the number of items intended to be added to the bloom filter (n) Capacity int // persistent storage Database Store // growth rate of the bloom filter (valid values are 2 and 4) GrowthRate GrowthRate // contains filtered or unexported fields }
BloomOptions is the options for creating a new bloom filter
type BoltStore ¶
type BoltStore struct {
// contains filtered or unexported fields
}
type GrowthRate ¶
type GrowthRate uint
var ( // GrowthSmall represents a small expected set growth GrowthSmall GrowthRate = 2 // GrowthLarge represents a large expected set growth GrowthLarge GrowthRate = 4 )
type ScalableBloomFilter ¶
type ScalableBloomFilter struct {
// contains filtered or unexported fields
}
func NewScalableBloom ¶
func NewScalableBloom(opts *BloomOptions) *ScalableBloomFilter
NewScalableBloom creates a new scalable bloom filter. err_rate is the desired false error rate. e.g. 0.001 implies 1 false positive in 1000 lookups initial_capacity is the initial capacity of the bloom filter. When the number of items exceed the initial capacity, a new filter is created.
The growth rate defaults to 2.
func (*ScalableBloomFilter) Add ¶
func (sbf *ScalableBloomFilter) Add(key []byte)
Add adds a key to the scalable bloom filter Complexity: O(k)
func (*ScalableBloomFilter) Capacity ¶
func (sbf *ScalableBloomFilter) Capacity() int
Size returns the total capacity of the scalable bloom filter
func (*ScalableBloomFilter) Clear ¶
func (sbf *ScalableBloomFilter) Clear()
Clear resets all bits in the bloom filter
func (*ScalableBloomFilter) Close ¶
func (sbf *ScalableBloomFilter) Close() error
Close closes the scalable bloom filter
func (*ScalableBloomFilter) Contains ¶
func (sbf *ScalableBloomFilter) Contains(key []byte) bool
Contains checks if the key is in the bloom filter Complexity: O(k*n)
func (*ScalableBloomFilter) Count ¶
func (sbf *ScalableBloomFilter) Count() int
Count returns the number of items added to the bloom filter
func (*ScalableBloomFilter) DB ¶
func (sbf *ScalableBloomFilter) DB() Store
DB returns the store used by the scalable bloom filter
func (*ScalableBloomFilter) Get ¶
func (sbf *ScalableBloomFilter) Get(key []byte) []byte
Get returns the value associated with the key
func (*ScalableBloomFilter) Put ¶
func (sbf *ScalableBloomFilter) Put(key, val []byte) error
Put adds a key to the scalable bloom filter, and puts the value in the database
func (*ScalableBloomFilter) Stats ¶
func (sbf *ScalableBloomFilter) Stats() BloomFilterStats
Stats returns the stats of the bloom filter
func (*ScalableBloomFilter) Top ¶
func (sbf *ScalableBloomFilter) Top() *BloomFilter
Top returns the top filter in the scalable bloom filter