nodes

package
v0.0.0-...-5f8ca62 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const BranchChildrenSize = 16

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchNode

type BranchNode struct {
	Children [BranchChildrenSize]Node
	Value    []byte

	Dirty bool
	// contains filtered or unexported fields
}

func NewBranchNode

func NewBranchNode() *BranchNode

func (*BranchNode) ChildCount

func (b *BranchNode) ChildCount() int

ChildCount returns the number of children the branch node has (i.e., non-nil children)

func (*BranchNode) ClearValue

func (b *BranchNode) ClearValue()

ClearValue clears value

func (*BranchNode) GetValue

func (b *BranchNode) GetValue() (value []byte, exists bool)

GetValue returns the value of the branch node and a boolean indicating its existence

func (*BranchNode) HasValue

func (b *BranchNode) HasValue() bool

HasValue checks if the branch node has a value

func (*BranchNode) SetChild

func (b *BranchNode) SetChild(nibble nibble.Nibble, node Node)

SetChild sets a specific child node in the branch node based on the given nibble

func (*BranchNode) SetValue

func (b *BranchNode) SetValue(value []byte)

SetValue sets value for branch node

type ExtensionNode

type ExtensionNode struct {
	Path  []nibble.Nibble
	Node  Node
	Dirty bool
}

func NewExtension

func NewExtension(path []nibble.Nibble, node Node) *ExtensionNode

type HashNode

type HashNode struct {
	Hash []byte
}

func NewHashNode

func NewHashNode(hash []byte) *HashNode

type LeafNode

type LeafNode struct {
	Path  []nibble.Nibble
	Value []byte
	Dirty bool
}

func NewLeafNode

func NewLeafNode(path []nibble.Nibble, value []byte) *LeafNode

type Node

type Node interface{}

Package nodes represents the various types of nodes used in a Merkle Patricia Trie (MPT). In the context of an MPT, there are three primary types of nodes:

  1. Leaf: A node that contains the end of a key and its associated value. Leaf nodes signify the end of a path in the trie and store the final data. The key is used to navigate through the trie, and when the end of the key is reached, the leaf's value is the data associated with that key.

  2. Extension: An intermediary node that has a shared key part and a single child. Extension nodes are used to represent the shared parts of keys to save space. They serve as a path compression mechanism to ensure the trie remains efficient and doesn't grow unnecessarily large with redundant information.

  3. Branch: A node that can have up to 16 children (based on hex values). This node type is used when there's a divergence in paths. Each child represents a potential continuation of the key, and traversal through the trie follows the path determined by the key's hex value at that depth. Additionally, a Branch node can also signify the end of a key if it holds a value directly, making it serve dual roles in the trie's structure.

Using these nodes, the MPT structures data in a way that allows for efficient lookups, updates, and deletions, while also ensuring cryptographic security and data integrity by means of hashing.

Jump to

Keyboard shortcuts

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