merkletrie

package
v0.22.119 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: ISC Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EmptyTrieHash represents the Merkle Hash of an empty PersistentTrie.
	// "0000000000000000000000000000000000000000000000000000000000000001"
	EmptyTrieHash  = &chainhash.Hash{1}
	NoChildrenHash = &chainhash.Hash{2}
	NoClaimsHash   = &chainhash.Hash{3}
)
View Source
var ErrFullRebuildRequired = errors.New("a full rebuild is required")

Functions

func NewCollapsedTrie

func NewCollapsedTrie() *collapsedTrie

Types

type KeyType

type KeyType []byte

type MerkleTrie

type MerkleTrie interface {
	SetRoot(h *chainhash.Hash) error
	Update(name []byte, h *chainhash.Hash, restoreChildren bool)
	MerkleHash() *chainhash.Hash
	MerkleHashAllClaims() *chainhash.Hash
	Flush() error
}

type PersistentTrie

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

PersistentTrie implements a 256-way prefix tree.

func NewPersistentTrie

func NewPersistentTrie(repo Repo) *PersistentTrie

NewPersistentTrie returns a PersistentTrie.

func (*PersistentTrie) Close

func (t *PersistentTrie) Close() error

func (*PersistentTrie) Dump

func (t *PersistentTrie) Dump(s string)

func (*PersistentTrie) Flush

func (t *PersistentTrie) Flush() error

func (*PersistentTrie) MerkleHash

func (t *PersistentTrie) MerkleHash() *chainhash.Hash

MerkleHash returns the Merkle Hash of the PersistentTrie. All nodes must have been resolved before calling this function.

func (*PersistentTrie) MerkleHashAllClaims

func (t *PersistentTrie) MerkleHashAllClaims() *chainhash.Hash

func (*PersistentTrie) SetRoot

func (t *PersistentTrie) SetRoot(h *chainhash.Hash) error

SetRoot drops all resolved nodes in the PersistentTrie, and set the Root with specified hash.

func (*PersistentTrie) Update

func (t *PersistentTrie) Update(name []byte, hash *chainhash.Hash, restoreChildren bool)

Update updates the nodes along the path to the key. Each node is resolved or created with their Hash cleared.

type RamTrie

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

func NewRamTrie

func NewRamTrie() *RamTrie

func (*RamTrie) Erase

func (pt *RamTrie) Erase(value KeyType) bool

func (*RamTrie) Find

func (pt *RamTrie) Find(value KeyType) *collapsedVertex

func (*RamTrie) FindPath

func (pt *RamTrie) FindPath(value KeyType) ([]int, []*collapsedVertex)

func (*RamTrie) Flush

func (rt *RamTrie) Flush() error

func (*RamTrie) InsertOrFind

func (pt *RamTrie) InsertOrFind(value KeyType) (bool, *collapsedVertex)

func (*RamTrie) IterateFrom

func (pt *RamTrie) IterateFrom(start KeyType, handler func(name KeyType, value *collapsedVertex) bool)

IterateFrom can be used to find a value and run a function on that value. If the handler returns true it continues to iterate through the children of value.

func (*RamTrie) MerkleHash

func (rt *RamTrie) MerkleHash() *chainhash.Hash

func (*RamTrie) MerkleHashAllClaims

func (rt *RamTrie) MerkleHashAllClaims() *chainhash.Hash

func (*RamTrie) NodeCount

func (pt *RamTrie) NodeCount() int

func (*RamTrie) SetRoot

func (rt *RamTrie) SetRoot(h *chainhash.Hash) error

func (*RamTrie) Update

func (rt *RamTrie) Update(name []byte, h *chainhash.Hash, _ bool)

type Repo

type Repo interface {
	Get(key []byte) ([]byte, io.Closer, error)
	Set(key, value []byte) error
	Close() error
	Flush() error
}

Repo defines APIs for PersistentTrie to access persistence layer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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