Documentation ¶
Overview ¶
Package patricia implements a patricia tree, or a radix tree with a radix of 2 -- creating an uneven binary tree.
Each entry is a key value pair. The key determines where the value is placed in the tree, with each bit of the key indicating a path. Values are arbitrary byte slices but only the SHA3-256 hash of the value is stored within the tree.
The nodes in the tree form an immutable persistent data structure, therefore Copy is a O(1) operation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPrefix = errors.New("key provided is a prefix to other keys")
ErrPrefix is returned from Insert or Delete if the key provided is a prefix to existing nodes.
Functions ¶
Types ¶
type Leaf ¶
Leaf describes a key and its corresponding hash of a value inserted into the patricia tree.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree implements a patricia tree.
func Reconstruct ¶
Reconstruct builds a tree with the provided leaf nodes.
func (*Tree) ContainsKey ¶
ContainsKey returns true if the key contains the provided key, without checking its corresponding hash.
func (*Tree) Delete ¶
Delete removes up to one value with a matching key. After removing the node, it will rearrange the tree to the optimal structure.
func (*Tree) Insert ¶
Insert enters data into the tree. If the key is not already present in the tree, a new node will be created and inserted, rearranging the tree to the optimal structure. If the key is present, the existing node is found and its value is updated, leaving the structure of the tree alone.