tree

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
	// IsEmpty returns true if the concrete type is in its default/empty state.
	IsEmpty() 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.

func NewIblt

func NewIblt(numBuckets int) *Iblt

NewIblt returns an *Iblt with default settings and specified number of buckets. numBuckets must be >= Iblt.k

func (*Iblt) Add

func (i *Iblt) Add(other Data) error

func (Iblt) Clone

func (i Iblt) Clone() Data

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)

Delete subtracts the key from the iblt and is the inverse of Insert.

func (*Iblt) Insert

func (i *Iblt) Insert(ref hash.SHA256Hash)

func (Iblt) IsEmpty added in v1.0.1

func (i Iblt) IsEmpty() bool

func (Iblt) MarshalBinary

func (i Iblt) MarshalBinary() ([]byte, error)

func (Iblt) New

func (i Iblt) New() Data

func (*Iblt) Subtract

func (i *Iblt) Subtract(other Data) error

func (*Iblt) UnmarshalBinary

func (i *Iblt) UnmarshalBinary(data []byte) error

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)
	// InsertGetDirty inserts a transaction reference like Insert and also returns the dirty leaves like GetUpdates.
	// This is an atomic operation to make sure no ResetUpdate can happen in between from calling logic.
	InsertGetDirty(ref hash.SHA256Hash, clock uint32) map[uint32][]byte
	// Delete a transaction reference without checking if ref is in the Tree
	Delete(ref hash.SHA256Hash, clock uint32)
	// GetRoot returns the accumulated Data for the entire tree
	GetRoot() Data
	// GetZeroTo 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
	GetZeroTo(clock uint32) (Data, uint32)
	// DropLeaves shrinks the tree by dropping all leaves. The parent of a leaf will become the new leaf.
	DropLeaves()
	// GetUpdates return the leaves that have been orphaned or updated since the last call to ResetUpdate.
	// dirty and orphaned are mutually exclusive.
	GetUpdates() (dirty map[uint32][]byte, orphaned []uint32)
	// ResetUpdate forgets all currently tracked changes.
	ResetUpdate()
	// Load builds a tree from binary leaf data. The keys in leaves correspond to a node's split value.
	Load(leaves map[uint32][]byte) error
}

Tree is the interface for an in-memory tree that provides fast access to Data over requested Lamport Clock ranges.

func New

func New(prototype Data, leafSize uint32) Tree

New creates a new tree with the given leafSize and of the same type of Data as the prototype. leafSize should be an even number.

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) Add

func (x *Xor) Add(data Data) error

func (*Xor) Clone

func (x *Xor) Clone() Data

func (*Xor) Delete added in v1.0.1

func (x *Xor) Delete(ref hash.SHA256Hash)

func (Xor) Hash

func (x Xor) Hash() hash.SHA256Hash

Hash returns a copy as a hash.SHA256Hash

func (*Xor) Insert

func (x *Xor) Insert(ref hash.SHA256Hash)

func (Xor) IsEmpty added in v1.0.1

func (x Xor) IsEmpty() bool

func (Xor) MarshalBinary

func (x Xor) MarshalBinary() ([]byte, error)

func (Xor) New

func (x Xor) New() Data

func (*Xor) Subtract

func (x *Xor) Subtract(data Data) error

func (*Xor) UnmarshalBinary

func (x *Xor) UnmarshalBinary(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL