Class FixedLeafTree

java.lang.Object
io.crums.util.mrkl.Tree
io.crums.util.mrkl.FixedLeafTree

public class FixedLeafTree
extends Tree
A more compact Tree appropriate if the leaves are fixed-width and it'all fits under 2 gigabytes.
See Also:
treeDataLength(int, int, int)
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int MIN_ALGO_WIDTH  
    static int MIN_LEAF_WIDTH  

    Fields inherited from class io.crums.util.mrkl.Tree

    BRANCH_PAD, LEAF_PAD
  • Constructor Summary

    Constructors
    Modifier Constructor Description
      FixedLeafTree​(int leaves, java.lang.String algo, byte[] data, int algoWidth, int leafWidth)
    Creates a new instance.
    protected FixedLeafTree​(FixedLeafTree copy)
    Copy constructor.
  • Method Summary

    Modifier and Type Method Description
    byte[] data​(int level, int index)
    Returns [a copy of] the data for the node at the specified coordinates.
    java.nio.ByteBuffer dataBlock()
    Returns entire data block.
    protected java.nio.ByteBuffer extraBlock()
    Returns the data beyond the standard definition of the tree.
    static boolean fitsModelCapacity​(int leaves, int algoWidth, int leafWidth)  
    int hashWidth()  
    int leafWidth()
    Returns the fixed-size leaf width.
    java.nio.ByteBuffer leavesBlock()
    Returns the leaves' data block.
    static int treeDataLength​(int leaves, int algoWidth, int leafWidth)
    Returns the number of bytes needed to encode the state of the tree, or -1 if that number exceeds the maximum int Java allows.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • FixedLeafTree

      public FixedLeafTree​(int leaves, java.lang.String algo, byte[] data, int algoWidth, int leafWidth) throws java.lang.IllegalArgumentException
      Creates a new instance.
      Parameters:
      leaves - number of leaf nodes in the tree
      algo - hash algo used for the trees internal nodes
      data - node data in serial form (interpreted by next parameters)
      algoWidth - number of bytes in the hash generated by algo
      leafWidth - number of bytes in a leaf node
      Throws:
      java.lang.IllegalArgumentException
    • FixedLeafTree

      protected FixedLeafTree​(FixedLeafTree copy)
      Copy constructor.
  • Method Details

    • data

      public byte[] data​(int level, int index)
      Description copied from class: Tree
      Returns [a copy of] the data for the node at the specified coordinates.
      Specified by:
      data in class Tree
      See Also:
      Node.data(), #data(int, int, ByteBuffer)
    • leafWidth

      public int leafWidth()
      Returns the fixed-size leaf width.
      Specified by:
      leafWidth in class Tree
      Returns:
      in bytes
    • dataBlock

      public java.nio.ByteBuffer dataBlock()
      Returns entire data block.
      Returns:
      a new read-only view of the entire block.
    • leavesBlock

      public java.nio.ByteBuffer leavesBlock()
      Returns the leaves' data block.
      Returns:
      a new read-only view of leaves' block.
    • extraBlock

      protected java.nio.ByteBuffer extraBlock()
      Returns the data beyond the standard definition of the tree. This is a view of whatever bytes remain in the data block after the tree definition.
      Returns:
      possibly empty extra block
    • hashWidth

      public int hashWidth()
    • fitsModelCapacity

      public static boolean fitsModelCapacity​(int leaves, int algoWidth, int leafWidth)
    • treeDataLength

      public static int treeDataLength​(int leaves, int algoWidth, int leafWidth)
      Returns the number of bytes needed to encode the state of the tree, or -1 if that number exceeds the maximum int Java allows.