Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidTrie indicates something wrong causing invalid operation ErrInvalidTrie = errors.New("invalid trie operation") // ErrNotExist indicates entry does not exist ErrNotExist = errors.New("not exist in trie") )
var ErrEndOfIterator = errors.New("hit the end of the iterator, no more item")
ErrEndOfIterator defines an error which will be returned
Functions ¶
func DefaultHashFunc ¶
DefaultHashFunc implements a default hash function
Types ¶
type Iterator ¶
Iterator iterates a trie
func NewLeafIterator ¶
NewLeafIterator returns a new leaf iterator
type KVStore ¶
type KVStore interface {
// Start starts the KVStore
Start(context.Context) error
// Stop stops the KVStore
Stop(context.Context) error
// Put puts key, value pair into KVStore
Put([]byte, []byte) error
// Delete deletes record from KVStore by key
Delete([]byte) error
// Get gets the value from KVStore by key
Get([]byte) ([]byte, error)
}
KVStore defines an interface for storing trie data as key-value pair
type LeafIterator ¶
type LeafIterator struct {
// contains filtered or unexported fields
}
LeafIterator defines an iterator to go through all the leaves under given node
type Node ¶
type Node interface {
// Type returns the type of a node
Type() NodeType
// Key returns the key of a node, only leaf has key
Key() []byte
// Value returns the value of a node, only leaf has value
Value() []byte
// contains filtered or unexported methods
}
Node defines the interface of a trie node Note: all the key-value pairs should be of the same length of keys
type Option ¶
Option sets parameters for SameKeyLenTrieContext construction parameter
func HashFuncOption ¶
HashFuncOption sets the hash func for the trie
func KVStoreOption ¶
KVStoreOption sets the kvstore for the trie
func KeyLengthOption ¶
KeyLengthOption sets the length of the keys saved in trie
func RootHashOption ¶
RootHashOption sets the root hash for the trie
func RootKeyOption ¶
RootKeyOption sets the root key for the trie
type Trie ¶
type Trie interface {
// Start starts the trie and the corresponding dependencies
Start(context.Context) error
// Stop stops the trie
Stop(context.Context) error
// Upsert inserts a new entry
Upsert([]byte, []byte) error
// Get retrieves an existing entry
Get([]byte) ([]byte, error)
// Delete deletes an entry
Delete([]byte) error
// RootHash returns trie's root hash
RootHash() []byte
// SetRootHash sets a new root to trie
SetRootHash([]byte) error
// DB returns the KVStore storing the node data
DB() KVStore
// contains filtered or unexported methods
}
Trie is the interface of Merkle Patricia Trie