Class MapNodeStore

java.lang.Object
com.norswap.nanoeth.trees.patricia.store.MapNodeStore
All Implemented Interfaces:
NodeStore

public final class MapNodeStore
extends Object
implements NodeStore
Key-value store implementation that stores key-values in an in-memory map (dictionary).
  • Constructor Details

    • MapNodeStore

      public MapNodeStore()
  • Method Details

    • extensionNode

      public PatriciaExtensionNode extensionNode​(Nibbles keyFragment, PatriciaBranchNode child)
      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 interface NodeStore
    • branchNode

      @SafeVarargs public final PatriciaBranchNode branchNode​(Pair<Nibbles,​PatriciaNode>... pairs)
      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 interface NodeStore
    • withValue

      public PatriciaBranchNode withValue​(PatriciaBranchNode branch, @Nullable @Retained byte[] value)
      Description copied from interface: NodeStore
      Returns a copy of branch with its value set to value (possibly null).

      The returned value must be added to the store, while branch must be removed from the store if not null.

      Specified by:
      withValue in interface NodeStore
    • withChild

      public PatriciaBranchNode withChild​(PatriciaBranchNode branch, int nibble, PatriciaNode child)
      Description copied from interface: NodeStore
      Returns a copy of branch with its child for the given nibble set to child.

      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.

      Specified by:
      withChild in interface NodeStore
    • getNode

      @Nullable public PatriciaNode getNode​(byte[] cap)
      Description copied from interface: NodeStore
      Return a node from its cap value, or null if no such node exists.
      Specified by:
      getNode in interface NodeStore
    • addNode

      public <T extends PatriciaNode> T addNode​(T node)
      Description copied from interface: NodeStore
      Adds a node to the store the returns it.
      Specified by:
      addNode in interface NodeStore
    • removeNode

      public void removeNode​(PatriciaNode node)
      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 interface NodeStore