Class FreeLeafTree

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

public class FreeLeafTree
extends Tree
A Tree allowing variable length leaves. Note although less efficient, this layout allows larger in-memory fixed-width trees than FixedLeafTree.
  • Constructor Details

    • FreeLeafTree

      public FreeLeafTree​(byte[][] data, int leaves, java.lang.String algo)
      Creates a new instance. Defensively copies.
      Parameters:
      data - double array of length 2 x leaves - 1
      leaves - the number of leaf nodes
      algo - the hashing algorithm
    • FreeLeafTree

      public FreeLeafTree​(byte[][] data, int leaves, java.lang.String algo, boolean copy)
      Creates a new instance.
      Parameters:
      data - double array of length 2 x leaves - 1
      leaves - the number of leaf nodes
      algo - the hashing algorithm
      copy - if true a defensive copy of data is used instead; if false, then data should not be modified
  • 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)
    • data

      public final byte[] data​(int serialIndex)
    • leafWidth

      public int leafWidth()

      Returns -1 signifying variable width. Note, it may coincidentally happen that all the leaves are fixed width. If you've specifically arranged for this, but are for some reason using this class instead of FixedLeafTree, then override this method to return its fixed value.

      Returns the leaf width in bytes if fixed; -1, otherwise (variable).
      Specified by:
      leafWidth in class Tree
      Returns:
      -1