Class Node

java.lang.Object
io.crums.util.mrkl.index.AbstractNode
io.crums.util.mrkl.Node

public class Node
extends AbstractNode
Merkle tree node. Besides its coordinates (level, index), each node holds data, which for internal nodes is a fixed-width signature. (The leaf nodes can be anything--including another signature.) Instances are immutable, so they're safe to pass around.

Navigation

Supports navigating to parent, siblings, and children--as well as random access. Note these access methods return a new object every time they're invoked. (This is to minimize the memory footprint of large trees.) Equality and hashCode semantics are properly implemented, so as long as you don't compare instances by reference, you'll be OK.
  • Field Summary

    Fields inherited from class io.crums.util.mrkl.index.AbstractNode

    FACTORY
  • Method Summary

    Modifier and Type Method Description
    byte[] data()
    Returns a copy of the node's data.
    Node getLeaf​(int index)
    Returns the leaf node at the given index.
    Node getRoot()
    Returns the root of the tree.
    boolean isCarry()  
    boolean isRight()
    Determines whether this node is the right child of its parent.
    boolean isRoot()  
    int leafCount()
    Returns the total number of leaves in the tree this node belongs to.
    Node leftChild()
    Returns this node's left child, or null if this node is a leaf.
    Node parent()
    Returns this node's parent, or null if this node is root.
    Node rightChild()
    Returns this node's right child, or null if this node is a leaf.
    int serialIndex()
    Returns the node's serial index.
    Node sibling()
    Returns the sibling that makes this node's parent, or null if this node is root.
    Tree tree()  
    boolean verify​(java.security.MessageDigest digest)
    Verifies the hash of this node against its children, if it hash any.

    Methods inherited from class io.crums.util.mrkl.index.AbstractNode

    equals, hashCode, index, isLeaf, isLeft, level, toString

    Methods inherited from class java.lang.Object

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

    • isRight

      public final boolean isRight()
      Description copied from class: AbstractNode
      Determines whether this node is the right child of its parent.

      Implementations should be marked final.

      Specified by:
      isRight in class AbstractNode
    • serialIndex

      public final int serialIndex()
      Returns the node's serial index. This is equal to the number of nodes preceding this node in a breadth-first traversal of the tree. The root node, therefore, returns 0; the last leaf returns 2 x leafCount - 2.
    • data

      public byte[] data()
      Returns a copy of the node's data.
    • verify

      public boolean verify​(java.security.MessageDigest digest)
      Verifies the hash of this node against its children, if it hash any.
    • isRoot

      public final boolean isRoot()
    • sibling

      public Node sibling()
      Returns the sibling that makes this node's parent, or null if this node is root.
    • parent

      public Node parent()
      Returns this node's parent, or null if this node is root.
    • leftChild

      public Node leftChild()
      Returns this node's left child, or null if this node is a leaf.
      See Also:
      AbstractNode.isLeaf()
    • rightChild

      public Node rightChild()
      Returns this node's right child, or null if this node is a leaf.
      See Also:
      AbstractNode.isLeaf()
    • getRoot

      public Node getRoot()
      Returns the root of the tree.
    • getLeaf

      public Node getLeaf​(int index) throws java.lang.IndexOutOfBoundsException
      Returns the leaf node at the given index.
      Parameters:
      index - zero-based index into leaf count
      Throws:
      java.lang.IndexOutOfBoundsException
      See Also:
      leafCount()
    • isCarry

      public final boolean isCarry()
    • leafCount

      public final int leafCount()
      Returns the total number of leaves in the tree this node belongs to.
    • tree

      public Tree tree()