Class PatriciaLeafNode

java.lang.Object
com.norswap.nanoeth.trees.patricia.PatriciaNode
com.norswap.nanoeth.trees.patricia.PatriciaLeafNode

public final class PatriciaLeafNode
extends PatriciaNode
A leaf in the patrica tree, which store the suffix of the key and its associated value.

Because a leaf node has no children, this implementation can be shared between multiple implementations.

  • Field Summary

    Fields
    Modifier and Type Field Description
    Nibbles keySuffix  
    byte[] value  

    Fields inherited from class com.norswap.nanoeth.trees.patricia.PatriciaNode

    cap
  • Constructor Summary

    Constructors
    Constructor Description
    PatriciaLeafNode​(Nibbles keySuffix, byte[] value)  
  • Method Summary

    Modifier and Type Method Description
    PatriciaNode add​(NodeStore store, Nibbles keySuffix, byte[] value)
    Returns the transformed node, after associating the given key with the given key suffix.
    void collectEntries​(NodeStore store, Nibbles prefix, Map<byte[],​byte[]> map)
    Adds all the entries store under this node to map, given that the prefix to reach this node is given by prefix.
    RLP compose()
    This method implements the structural composition function c (equation 197 and previous in the yellowpaper).
    boolean equals​(Object o)  
    int hashCode()  
    byte[] lookup​(NodeStore store, Nibbles keySuffix)
    Lookup the entry with the given key suffix, the suffix of a sequence of nibbles, where the missing prefix was used to reach the present node.
    PatriciaNode remove​(NodeStore store, Nibbles keySuffix)
    Returns the transformed node, after removing the entry for the given key suffix (if any), or returns null if the removal of the key means that the node itself must disappear.
    BranchStep step​(NodeStore store, Nibbles keySuffix)
    Returns a qudruplet of: this node.
    String toString()  
    byte[] value()
    Returns the value associated with the node, or null if no value is associated.

    Methods inherited from class com.norswap.nanoeth.trees.patricia.PatriciaNode

    cap, merkleRoot, parse

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • keySuffix

      public final Nibbles keySuffix
    • value

      public final byte[] value
  • Constructor Details

    • PatriciaLeafNode

      public PatriciaLeafNode​(Nibbles keySuffix, @Retained byte[] value)
  • Method Details

    • value

      public byte[] value()
      Description copied from class: PatriciaNode
      Returns the value associated with the node, or null if no value is associated.
      Specified by:
      value in class PatriciaNode
    • step

      public BranchStep step​(NodeStore store, Nibbles keySuffix)
      Description copied from class: PatriciaNode
      Returns a qudruplet of:
      1. this node.
      2. the child in which to look for the value for the given key suffix (or equivalently, the child to modify to insert a value to be associated with the given key suffix). Can be null if no such child exists.
      3. the number of nibbles shared between this node and the key suffix. For leaf and extension node, this will be the length of the shared prefix the key suffix and the node's key fragment. For branch nodes, this will be 0 if the returned node is this and 1 otherwise.
      4. the number of nibbles left in the key suffix after deducting the shared nibbles.
      Specified by:
      step in class PatriciaNode
    • lookup

      public byte[] lookup​(NodeStore store, Nibbles keySuffix)
      Description copied from class: PatriciaNode
      Lookup the entry with the given key suffix, the suffix of a sequence of nibbles, where the missing prefix was used to reach the present node.

      This must handle empty nibble sequences.

      Specified by:
      lookup in class PatriciaNode
    • add

      public PatriciaNode add​(NodeStore store, Nibbles keySuffix, byte[] value)
      Description copied from class: PatriciaNode
      Returns the transformed node, after associating the given key with the given key suffix.

      This must handle empty nibble sequences.

      The method must add its return value to the store, and remove the current node from the store. Any other node added/removed from the tree in the process must similarly be added/removed from the store.

      Specified by:
      add in class PatriciaNode
    • remove

      public PatriciaNode remove​(NodeStore store, Nibbles keySuffix)
      Description copied from class: PatriciaNode
      Returns the transformed node, after removing the entry for the given key suffix (if any), or returns null if the removal of the key means that the node itself must disappear.

      This must handle empty nibble sequences.

      The method must add its return value to the store, and remove the current node from the store. Any other node added/removed from the tree in the process must similarly be added/removed from the store.

      Specified by:
      remove in class PatriciaNode
    • compose

      public RLP compose()
      Description copied from class: PatriciaNode
      This method implements the structural composition function c (equation 197 and previous in the yellowpaper). See the README of this package for more information.
      Specified by:
      compose in class PatriciaNode
    • collectEntries

      public void collectEntries​(NodeStore store, Nibbles prefix, Map<byte[],​byte[]> map)
      Description copied from class: PatriciaNode
      Adds all the entries store under this node to map, given that the prefix to reach this node is given by prefix.
      Specified by:
      collectEntries in class PatriciaNode
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object