Documentation
¶
Index ¶
- Variables
- type Data
- type Iblt
- func (i *Iblt) Add(other Data) error
- func (i *Iblt) Clone() Data
- func (i *Iblt) Decode() (remaining []hash.SHA256Hash, missing []hash.SHA256Hash, err error)
- func (i *Iblt) Delete(key hash.SHA256Hash)
- func (i *Iblt) Empty() bool
- func (i *Iblt) Insert(ref hash.SHA256Hash)
- func (i *Iblt) MarshalBinary() ([]byte, error)
- func (i *Iblt) New() Data
- func (i *Iblt) Subtract(other Data) error
- func (i *Iblt) UnmarshalBinary(data []byte) error
- type Tree
- type Xor
- func (x *Xor) Add(data Data) error
- func (x *Xor) Clone() Data
- func (x *Xor) Delete(ref hash.SHA256Hash)
- func (x *Xor) Empty() bool
- func (x *Xor) Hash() hash.SHA256Hash
- func (x *Xor) Insert(ref hash.SHA256Hash)
- func (x *Xor) MarshalBinary() ([]byte, error)
- func (x *Xor) New() Data
- func (x *Xor) Subtract(data Data) error
- func (x *Xor) UnmarshalBinary(data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrDecodeNotPossible = errors.New("decode failed") ErrDecodeLoop = errors.New("decode loop detected") )
ErrDecodeNotPossible is returned when the Iblt cannot be decoded.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data interface {
// New creates a new instance, of the same concrete type, initialized to the default/empty state.
New() Data
// Clone creates an exact copy using the current instance as a prototype.
Clone() Data
// Insert a new transaction reference.
Insert(ref hash.SHA256Hash)
// Delete a transaction reference.
Delete(ref hash.SHA256Hash)
// Add other Data to this one. Returns an error if the underlying datastructures are incompatible.
Add(other Data) error
// Subtract other Data from this one. Returns an error if the underlying datastructures are incompatible.
Subtract(other Data) error
// Empty returns true if the concrete type is in its default/empty state.
Empty() bool
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
}
Data is the interface for data held in each node of the Tree
type Iblt ¶
type Iblt struct {
// contains filtered or unexported fields
}
Iblt implements an Invertible Bloom Filter, which is the special case of an IBLT where the key-value pair consist of a key-hash(key) pair. The hash(key) value ensures correct decoding after subtraction of two IBLTs. Iblt is not thread-safe.
- Goodrich, Michael T., and Michael Mitzenmacher. "Invertible bloom lookup tables." http://arxiv.org/pdf/1101.2245
- Eppstein, David, et al. "What's the difference?: efficient set reconciliation without prior context." http://conferences.sigcomm.org/sigcomm/2011/papers/sigcomm/p218.pdf
func NewIblt ¶
NewIblt returns an *Iblt with default settings and specified number of buckets. numBuckets must be >= Iblt.k
func (*Iblt) Decode ¶
func (i *Iblt) Decode() (remaining []hash.SHA256Hash, missing []hash.SHA256Hash, err error)
Decode tries to deconstruct the iblt into hashes remaining (positive entries) and missing (negative entries) from the iblt. Decode is destructive to the iblt. If decoding fails with ErrDecodeNotPossible, the original iblt can be recovered by Insert-ing all remaining and Delete-ing all missing hashes. Any other error is unrecoverable.
func (*Iblt) Delete ¶
func (i *Iblt) Delete(key hash.SHA256Hash)
func (*Iblt) Insert ¶
func (i *Iblt) Insert(ref hash.SHA256Hash)
func (*Iblt) MarshalBinary ¶
func (*Iblt) UnmarshalBinary ¶
type Tree ¶
type Tree interface {
// Insert a transaction reference at the specified clock value.
// The result of inserting the same ref multiple times is undefined.
Insert(ref hash.SHA256Hash, clock uint32)
// Delete a transaction reference without checking if ref is in the Tree
Delete(ref hash.SHA256Hash, clock uint32)
// Root returns the accumulated Data for the entire tree
Root() Data
// ZeroTo returns the LC value closest to the requested clock value together with Data of the same leaf/page.
// The LC value closest to requested clock is defined as the lowest of:
// - highest LC known to the Tree
// - highest LC of the leaf that clock is on: ceil(clock/leafSize)*leafSize - 1
ZeroTo(clock uint32) (Data, uint32)
// DropLeaves shrinks the tree by dropping all leaves. The parent of a leaf will become the new leaf.
DropLeaves()
// Updates return the leaves that have been orphaned or updated since the last call to ResetUpdate.
// dirty and orphaned are mutually exclusive.
Updates() (dirty map[uint32][]byte, orphaned []uint32)
// ResetUpdates forgets all currently tracked changes.
ResetUpdates()
// Load builds a tree from binary leaf data. The keys in leaves correspond to a node's split value.
// All consecutive leaves must be present. Gaps must be filled with zero value of the corresponding Data implementation.
Load(leaves map[uint32][]byte) error
// Replace replaces the Data at the leaf starting with the given clock value with the given Data.
// It adds the leaf to the dirtyLeaves map.
Replace(clock uint32, data Data) error
}
Tree is the interface for an in-memory tree that provides fast access to Data over requested Lamport Clock ranges. The tree is not thread safe
type Xor ¶
type Xor hash.SHA256Hash
Xor is an alias of hash.SHA256Hash that implements tree.Data to track transaction xors
func NewXor ¶
func NewXor() *Xor
NewXor returns new(Xor). Convenience function to provide a consistent interface
func (*Xor) Delete ¶
func (x *Xor) Delete(ref hash.SHA256Hash)
func (*Xor) Insert ¶
func (x *Xor) Insert(ref hash.SHA256Hash)