trie

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChildStorageKeyPrefix = []byte(":child_storage:default:")

ChildStorageKeyPrefix is the prefix for all child storage keys

View Source
var EmptyHash, _ = NewEmptyTrie().Hash()

nolint

Functions

This section is empty.

Types

type Hasher

type Hasher struct {
	// contains filtered or unexported fields
}

Hasher is a wrapper around a hash function

func NewHasher

func NewHasher() (*Hasher, error)

NewHasher create new Hasher instance

func (*Hasher) Hash

func (h *Hasher) Hash(n node) (res []byte, err error)

Hash encodes the node and then hashes it if its encoded length is > 32 bytes

type Test

type Test struct {
	// contains filtered or unexported fields
}

Test represents a key-value pair for a test

func GenerateRandomTests

func GenerateRandomTests(t *testing.T, size int) []Test

GenerateRandomTests returns an array of random Tests

func (*Test) Key

func (t *Test) Key() []byte

Key returns the test key

func (*Test) Value

func (t *Test) Value() []byte

Value returns the test value

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

Trie is a Merkle Patricia Trie. The zero value is an empty trie with no database. Use NewTrie to create a trie that sits on top of a database.

func NewEmptyTrie

func NewEmptyTrie() *Trie

NewEmptyTrie creates a trie with a nil root

func NewTrie

func NewTrie(root node) *Trie

NewTrie creates a trie with an existing root node

func (*Trie) ClearFromChild added in v0.2.0

func (t *Trie) ClearFromChild(keyToChild, key []byte) error

ClearFromChild removes the child storage entry

func (*Trie) Decode

func (t *Trie) Decode(enc []byte) error

Decode decodes a trie from the DB and sets the receiver to it The encoded trie must have been encoded with t.Encode

func (*Trie) DeepCopy added in v0.2.0

func (t *Trie) DeepCopy() (*Trie, error)

DeepCopy makes a new trie and copies over the existing trie into the new trie

func (*Trie) Delete

func (t *Trie) Delete(key []byte) error

Delete removes any existing value for key from the trie.

func (*Trie) DeleteFromChild added in v0.2.0

func (t *Trie) DeleteFromChild(keyToChild []byte) error

DeleteFromChild deletes from child storage

func (*Trie) Encode

func (t *Trie) Encode() ([]byte, error)

Encode traverses the trie recursively, encodes each node, SCALE encodes the encoded node, and appends them all together

func (*Trie) EncodeRoot

func (t *Trie) EncodeRoot() ([]byte, error)

EncodeRoot returns the encoded root of the trie

func (*Trie) Entries

func (t *Trie) Entries() map[string][]byte

Entries returns all the key-value pairs in the trie as a map of keys to values

func (*Trie) Get

func (t *Trie) Get(key []byte) (value []byte, err error)

Get returns the value for key stored in the trie at the corresponding key

func (*Trie) GetChild

func (t *Trie) GetChild(keyToChild []byte) (*Trie, error)

GetChild returns the child trie at key :child_storage:[keyToChild]

func (*Trie) GetFromChild

func (t *Trie) GetFromChild(keyToChild, key []byte) ([]byte, error)

GetFromChild retrieves a key-value pair from the child trie located in the main trie at key :child_storage:[keyToChild]

func (*Trie) GetKeysWithPrefix added in v0.2.0

func (t *Trie) GetKeysWithPrefix(prefix []byte) [][]byte

GetKeysWithPrefix returns all keys in the trie that have the given prefix

func (*Trie) Hash

func (t *Trie) Hash() (common.Hash, error)

Hash returns the hashed root of the trie

func (*Trie) Load

func (t *Trie) Load(data map[string]string) error

Load data into trie

func (*Trie) MustHash added in v0.2.0

func (t *Trie) MustHash() common.Hash

MustHash returns the hashed root of the trie. It panics if it fails to hash the root node.

func (*Trie) NextKey added in v0.2.0

func (t *Trie) NextKey(key []byte) []byte

NextKey returns the next key in the trie in lexicographic order. It returns nil if there is no next key

func (*Trie) Print

func (t *Trie) Print()

Print prints the trie through pre-order traversal

func (*Trie) PrintEncoding

func (t *Trie) PrintEncoding()

PrintEncoding prints the trie with node encodings through pre-order traversal

func (*Trie) Put

func (t *Trie) Put(key, value []byte) error

Put inserts a key with value into the trie

func (*Trie) PutChild

func (t *Trie) PutChild(keyToChild []byte, child *Trie) error

PutChild inserts a child trie into the main trie at key :child_storage:[keyToChild]

func (*Trie) PutIntoChild

func (t *Trie) PutIntoChild(keyToChild, key, value []byte) error

PutIntoChild puts a key-value pair into the child trie located in the main trie at key :child_storage:[keyToChild]

func (*Trie) RootNode

func (t *Trie) RootNode() node

RootNode returns the root of the trie

func (*Trie) String

func (t *Trie) String() string

String returns the trie stringified through pre-order traversal

func (*Trie) StringWithEncoding

func (t *Trie) StringWithEncoding() string

StringWithEncoding returns the trie stringified as well as the encoding of each node

Jump to

Keyboard shortcuts

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