Documentation
¶
Index ¶
- Variables
- type Cell
- func (c *Cell) Clone() *Cell
- func (c *Cell) GetCount() int64
- func (c *Cell) GetDigest() uint64
- func (c *Cell) GetKey() []byte
- func (c *Cell) Insert(key []byte, digest uint64)
- func (c *Cell) Invert()
- func (c *Cell) IsEmpty() bool
- func (c *Cell) IsPure(h *Hash) bool
- func (c *Cell) Remove(key []byte, digest uint64)
- func (c *Cell) Subtract(cell *Cell)
- func (c *Cell) Union(cell *Cell)
- type Hash
- type IBF
- func (i *IBF) Clone() (clone *IBF)
- func (i *IBF) GetCardinality() int64
- func (i *IBF) GetCells() []*Cell
- func (i *IBF) GetSize() uint64
- func (i *IBF) Insert(key []byte)
- func (i *IBF) Invert()
- func (i *IBF) IsEmpty() bool
- func (i *IBF) Pop() ([]byte, error)
- func (i *IBF) Remove(key []byte)
- func (i *IBF) Subtract(other *IBF)
- func (i *IBF) Union(other *IBF)
Constants ¶
This section is empty.
Variables ¶
var ( Error = errs.Class("ibf") ErrNoPureCell = Error.New("no pure cell") ErrEmptySet = Error.New("empty set") )
Errors for this package.
Functions ¶
This section is empty.
Types ¶
type Cell ¶
type Cell struct {
Key *block `json:"key"`
Digest uint64 `json:"digest"`
Count int64 `json:"count"`
}
Cell contains the state of an individual position in an IBF.
func (*Cell) Insert ¶
Insert adds the key with the given digest to this cell.
NOTE: This assumes the key does not already exist in the cell. If it does this effectively removes it and the count will be incorrect.
func (*Cell) IsEmpty ¶
IsEmpty returns true if the cell's count is zero, key is empty, and digest is zero.
func (*Cell) IsPure ¶
IsPure returns true if the cell contains exactly one value and the hash is valid.
func (*Cell) Remove ¶
Remove deletes the key with the given digest from this cell.
NOTE: This assumes the key already exists in the cell. If it does not this effectively adds it and the count will be incorrect.
type Hash ¶
type Hash struct {
Key [2]uint64 `json:"key"`
}
Hash maintains the state for a siphash hasher.
type IBF ¶
type IBF struct {
Positioners []*Hash `json:"positioners"`
Hasher *Hash `json:"hasher"`
Size uint64 `json:"size"`
Cells []*Cell `json:"cells"`
Cardinality int64 `json:"cardinality"`
}
IBF holds the state of an invertable bloom filter.
func NewIBF ¶
NewIBF creates a new IBF of the given size. An IBF can accurately handle differences of approximately 2/3rds the configured size (e.g. a size of 100 would allow for ~66 differences to be accurately retrieved). 3 positioners and a hasher are created using the output from a random number generator initialized with the seed.
func NewIBFWithHash ¶
NewIBFWithHash creates a new IBF with the provided positioners and hasher. It will use the given hashers for positioning and computing the key hashes. The positioners must all be initialized with different seeds to ensure they do not produce the same positions for the same key.
func (*IBF) GetCardinality ¶
GetCardinality returns the IBF's cardinality.
func (*IBF) Insert ¶
Insert adds the key to the set.
NOTE: This does not know if the key already exists and will add it unconditionally. If the key did already exist in the set, then that effectively would remove it!
func (*IBF) Invert ¶
func (i *IBF) Invert()
Invert flips the cardinality of the set and the cells. As if all elements has instead been removed from the set instead of added.
func (*IBF) Pop ¶
Pop finds a key in a pure cell, removes it from the set, and returns it. If no pure cell can be found it returns ErrNoPureCell indicating that there are more elements in the set, but they cannot be popped. If the set is empty it returns ErrEmptySet.
func (*IBF) Remove ¶
Remove deletes the key from the set.
NOTE: This does not know if the key already exists and will add it unconditionally. If the key did already exist in the set, then that effectively would add it!
func (*IBF) Subtract ¶
Subtract removes all the elements from the provided set from this set.
NOTE: This assumes the other set is a subset of this one. If that isn't true then this will actually perform a symmetric difference and the cardinality will be incorrect! If the two sets are not configured the same then the behavior is undefined and could potentially panic.
func (*IBF) Union ¶
Union inserts all the elements from the provided set to this set.
NOTE: This assumes the two sets are disjoint and configured the same. If the two sets are not disjoint this will actually perform a symmetric difference and the cardinality will be incorrect! If the two sets are not configured the same then the behavior is undefined and could potentially panic.