Class TreeNodeStore
- All Implemented Interfaces:
NodeStore
public final class TreeNodeStore extends Object implements NodeStore
The in-memory tree does not have "a store", since children are kept directly in the nodes, so
the data access method are no-op, excepted getNode(byte[])
which throws an exception.
-
Constructor Summary
Constructors Constructor Description TreeNodeStore()
-
Method Summary
Modifier and Type Method Description <T extends PatriciaNode>
TaddNode(T node)
Adds a node to the store the returns it.PatriciaBranchNode
branchNode(Pair<Nibbles,PatriciaNode>... pairs)
Returns a new branch node with the give children.PatriciaExtensionNode
extensionNode(Nibbles keyFragment, PatriciaBranchNode child)
Returns a new extension node with the given key fragment and child node.PatriciaNode
getNode(byte[] cap)
Return a node from its cap value, or null if no such node exists.void
removeNode(PatriciaNode node)
Removes the node from the store.PatriciaBranchNode
withChild(PatriciaBranchNode branch, int nibble, PatriciaNode child)
Returns a copy ofbranch
with its child for the givennibble
set tochild
.PatriciaBranchNode
withValue(PatriciaBranchNode branch, byte[] value)
Returns a copy ofbranch
with its value set tovalue
(possibly null).
-
Constructor Details
-
TreeNodeStore
public TreeNodeStore()
-
-
Method Details
-
extensionNode
Description copied from interface:NodeStore
Returns a new extension node with the given key fragment and child node.The returned value must be added to the store, nothing should be done with the child.
- Specified by:
extensionNode
in interfaceNodeStore
-
branchNode
Description copied from interface:NodeStore
Returns a new branch node with the give children.If the nibbles part of a pair is empty, the child must be a leaf node, and its value will be used as the value of the branch node. Otherwise the node will be inserted into the new branch node, potentially after being extended as an extension node or longer leaf node to accomodate the remaining nibbles past the first (which is "consumed" by the branch node).
The returned value must be added to the store, nothing should be done with the children.
- Specified by:
branchNode
in interfaceNodeStore
-
withValue
Description copied from interface:NodeStore
Returns a copy ofbranch
with its value set tovalue
(possibly null).The returned value must be added to the store, while
branch
must be removed from the store if not null. -
withChild
Description copied from interface:NodeStore
Returns a copy ofbranch
with its child for the givennibble
set tochild
.child
is allowed to be null, but it is the responsability of the caller to ensure that the returned node is valid (i.e. has at a least a child and a value or two children).The returned value must be added to the store, while
branch
must be removed from the store. Nothing should be done with the child. -
getNode
Description copied from interface:NodeStore
Return a node from its cap value, or null if no such node exists. -
addNode
Description copied from interface:NodeStore
Adds a node to the store the returns it. -
removeNode
Description copied from interface:NodeStore
Removes the node from the store.The behaviour is implementation-defined, and in particular, this does not guarantee that after calling this method
getNode(node.cap())
will return null.The major example is that for the chain state, reorgs are possible, so we want to keep old nodes around. However, we might want to record which block removed which nodes, so that we may eventually prune the tree.
- Specified by:
removeNode
in interfaceNodeStore
-