trie

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag int

Flag to identify the type of node

type Node

type Node struct {
	Hash  *crypto.HashType
	Value [][]byte
}

Node in trie. Branch [hash_0, hash_1, ..., hash_f] Extension [path, next hash] Leaf [path, value, terminator]

func (*Node) BranchLen

func (n *Node) BranchLen() int

BranchLen returns the length of branch node.

func (*Node) FirstSubNodeHashInBranch

func (n *Node) FirstSubNodeHashInBranch() (*crypto.HashType, int)

FirstSubNodeHashInBranch returns the first sub node hash in branch node.

func (*Node) FromProtoMessage

func (n *Node) FromProtoMessage(msg proto.Message) error

FromProtoMessage converts proto message to node.

func (*Node) Marshal

func (n *Node) Marshal() (data []byte, err error)

Marshal method marshal node object to binary

func (*Node) ToProtoMessage

func (n *Node) ToProtoMessage() (proto.Message, error)

ToProtoMessage converts node to proto message.

func (*Node) Type

func (n *Node) Type() Flag

Type returns the type of node.

func (*Node) Unmarshal

func (n *Node) Unmarshal(data []byte) error

Unmarshal method unmarshal binary data to node object

type Trie

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

Trie is a Merkle Patricia Trie.

func New

func New(rootHash *crypto.HashType, db storage.Table) (*Trie, error)

New creates a trie with an existing root hash from db.

func (*Trie) Commit

func (t *Trie) Commit() (*crypto.HashType, error)

Commit persistent the data of the trie.

func (*Trie) Delete

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

Delete node in the trie.

func (*Trie) Get

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

Get value by key in the trie.

func (*Trie) Hash

func (t *Trie) Hash() crypto.HashType

Hash return root hash of trie.

func (*Trie) String

func (t *Trie) String() string

String print the Trie.

func (*Trie) Update

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

Update key with value in the trie.

Jump to

Keyboard shortcuts

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