Class DeltaTree

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

public class DeltaTree extends Tree
A Merkle tree constructed from another with more leaves appended. The "delta" in the name refers not to deletions, but to the fact the data added and computed is incremental even when the base tree is arbitrarily large.
See Also:
  • Constructor Details

    • DeltaTree

      public DeltaTree(Tree base, byte[] deltaNodes)
      Creates a new instance.
      Parameters:
      base - the base tree
      deltaNodes - new nodes of the tree. (Careful you don't create garbage.)
      See Also:
    • DeltaTree

      protected DeltaTree(DeltaTree copy)
      Copy constructor.
  • Method Details

    • computeNewLeafCount

      public static int computeNewLeafCount(Tree base, byte[] deltaNodes) throws IllegalArgumentException
      Infers and returns the number of leaves in the new tree given an array of deltas (additions) from a base tree.
      Parameters:
      base - an omni-width base tree (expected to be large)
      deltaNodes - data array of length that is a multiple of Tree.hashAlgoWidth()
      Returns:
      the new number of leaves
      Throws:
      IllegalArgumentException
    • 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()
      Description copied from class: Tree
      Returns the leaf width in bytes if fixed; -1, otherwise (variable).
      Specified by:
      leafWidth in class Tree