Documentation ¶
Index ¶
- Variables
- func DefaultHashFunc(data []byte) []byte
- type HashFunc
- type Iterator
- type KVStore
- type LeafIterator
- type Node
- type NodeType
- type Option
- type Trie
- type TwoLayerTrie
- func (tlt *TwoLayerTrie) Delete(layerOneKey []byte, layerTwoKey []byte) error
- func (tlt *TwoLayerTrie) Get(layerOneKey []byte, layerTwoKey []byte) ([]byte, error)
- func (tlt *TwoLayerTrie) RootHash() []byte
- func (tlt *TwoLayerTrie) SetRootHash(rh []byte) error
- func (tlt *TwoLayerTrie) Start(ctx context.Context) error
- func (tlt *TwoLayerTrie) Stop(ctx context.Context) error
- func (tlt *TwoLayerTrie) Upsert(layerOneKey []byte, layerTwoKey []byte, value []byte) error
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
func NewKVStore ¶ added in v0.11.0
func NewKVStore(bucket string, dao db.KVStoreBasic) (KVStore, error)
NewKVStore creates a new KVStore
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 // IsEmpty returns true is this is an empty trie IsEmpty() bool // DB returns the KVStore storing the node data DB() KVStore // contains filtered or unexported methods }
Trie is the interface of Merkle Patricia Trie
type TwoLayerTrie ¶ added in v0.11.0
type TwoLayerTrie struct {
// contains filtered or unexported fields
}
TwoLayerTrie is a trie data structure with two layers
func NewTwoLayerTrie ¶ added in v0.11.0
func NewTwoLayerTrie(dbForTrie KVStore, rootKey string) *TwoLayerTrie
NewTwoLayerTrie creates a two layer trie
func (*TwoLayerTrie) Delete ¶ added in v0.11.0
func (tlt *TwoLayerTrie) Delete(layerOneKey []byte, layerTwoKey []byte) error
Delete deletes an item in layer two
func (*TwoLayerTrie) Get ¶ added in v0.11.0
func (tlt *TwoLayerTrie) Get(layerOneKey []byte, layerTwoKey []byte) ([]byte, error)
Get returns the value in layer two
func (*TwoLayerTrie) RootHash ¶ added in v0.11.0
func (tlt *TwoLayerTrie) RootHash() []byte
RootHash returns the layer one trie root
func (*TwoLayerTrie) SetRootHash ¶ added in v0.11.0
func (tlt *TwoLayerTrie) SetRootHash(rh []byte) error
SetRootHash sets root hash for layer one trie
func (*TwoLayerTrie) Start ¶ added in v0.11.0
func (tlt *TwoLayerTrie) Start(ctx context.Context) error
Start starts the layer one trie