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:
  • Field Details

  • Constructor Details

    • FixedLeafTree

      public FixedLeafTree(int leaves, String algo, byte[] data, int algoWidth, int leafWidth) throws 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:
      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. For internal nodes, this is just the node's hash, which is computed from the hash of its child nodes; for leaf nodes, the node's data may generally be anything, but more often than not it's the hash of a source object.
      Specified by:
      data in class Tree
      See Also:
    • leafWidth

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

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

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

      protected 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.