Class DeltaBuilder

java.lang.Object

public class DeltaBuilder
extends FixedLeafBuilder
Builds an incrementally bigger tree by only recalculating and maintaining deltas. Note this is an implementation path to building file-backed trees that would otherwise have trouble fitting in memory.
See Also:
DeltaTree
  • Field Summary

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

    copyOnWrite, data, digest, lock
  • Constructor Summary

    Constructors
    Constructor Description
    DeltaBuilder​(Tree tree)
    Constructs a copy-on-write instance.
    DeltaBuilder​(Tree tree, boolean copyOnWrite)
    Creates a new instance.
  • Method Summary

    Modifier and Type Method Description
    int add​(byte[] item, int off, int len)
    Items only the width of the (hash) digest width are allowed because this is an omni-width tree.
    Tree build()
    Builds and returns the tree.
    void clear()
    Clears the state of the instance, as if new.
    int itemsAdded()
    Returns the total number of items added (appended).
    protected DeltaTree packageTree()  

    Methods inherited from class io.crums.util.mrkl.FixedLeafBuilder

    leafWidth

    Methods inherited from class io.crums.util.mrkl.Builder

    add, completeTree, count, getHashAlgo, hash, hashWidth, item, level, levelSize, newByteArrayList

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DeltaBuilder

      public DeltaBuilder​(Tree tree)
      Constructs a copy-on-write instance.
      Parameters:
      tree - the base tree to start from
      See Also:
      DeltaBuilder(Tree, boolean)
    • DeltaBuilder

      public DeltaBuilder​(Tree tree, boolean copyOnWrite)
      Creates a new instance.
      Parameters:
      tree - the base tree to start from
      copyOnWrite - if true, then every Builder.add(byte[]) is argument is copied (the argument's value is considered volatile). When you know you won't be modifying the input arguments set this to false
  • Method Details

    • build

      public Tree build()
      Description copied from class: Builder
      Builds and returns the tree. On return the builder is cleared.
      Overrides:
      build in class FixedLeafBuilder
      See Also:
      Builder.clear()
    • packageTree

      protected DeltaTree packageTree()
      Overrides:
      packageTree in class FixedLeafBuilder
    • clear

      public void clear()
      Description copied from class: Builder
      Clears the state of the instance, as if new.
      Overrides:
      clear in class Builder
    • add

      public int add​(byte[] item, int off, int len) throws java.lang.IndexOutOfBoundsException

      Items only the width of the (hash) digest width are allowed because this is an omni-width tree.

      Adds the specified item as the next leaf node are returns its leaf index.
      Overrides:
      add in class FixedLeafBuilder
      Parameters:
      item - the item's data (copied)
      off - starting offset into item
      len - = FixedLeafBuilder.leafWidth()
      Returns:
      the item's leaf node index in the to-be built tree
      Throws:
      java.lang.IndexOutOfBoundsException
    • itemsAdded

      public int itemsAdded()
      Returns the total number of items added (appended).