merkle

package
v0.14.13 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: AGPL-3.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tree

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

Tree represents a binary patricia merkle tree. The difference with a normal merkle tree is that it compresses paths that lead to a single leaf into a single intermediary node, which makes it significantly more space-efficient and a lot harder to exploit for denial-of-service attacks. On the downside, it makes insertions and deletions more complex, as we need to split nodes and merge them, depending on whethere their are leaves or not.

func NewTree

func NewTree() *Tree

NewTree creates a new empty patricia merkle tree.

func (*Tree) Del

func (t *Tree) Del(key []byte) bool

Del will remove the value associated with the given key from the patricia merkle trie. It will return true if they key was found and false otherwise. Internally, any parent nodes between the leaf up to the closest shared path will be deleted or merged, which keeps the trie deterministic regardless of insertion and deletion orders.

func (*Tree) Get

func (t *Tree) Get(key []byte) (interface{}, bool)

Get will retrieve the value associated with the given key. It returns true if the key was found and false otherwise.

func (*Tree) Hash

func (t *Tree) Hash() []byte

Hash will return the root hash of this patricia merkle tree.

func (*Tree) Put

func (t *Tree) Put(key []byte, val interface{}) bool

Put will stores the given value in the trie under the given key. If the key already exists, it will replace the value and return true.

Jump to

Keyboard shortcuts

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