Package io.crums.util.mrkl
Class DeltaBuilder
java.lang.Object
io.crums.util.mrkl.Builder
io.crums.util.mrkl.FixedLeafBuilder
io.crums.util.mrkl.DeltaBuilder
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
Constructs a copy-on-write instance.- Parameters:
tree
- the base tree to start from- See Also:
DeltaBuilder(Tree, boolean)
-
DeltaBuilder
Creates a new instance.- Parameters:
tree
- the base tree to start fromcopyOnWrite
- 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
Description copied from class:Builder
Builds and returns the tree. On return the builder is cleared.- Overrides:
build
in classFixedLeafBuilder
- See Also:
Builder.clear()
-
packageTree
- Overrides:
packageTree
in classFixedLeafBuilder
-
clear
public void clear()Description copied from class:Builder
Clears the state of the instance, as if new. -
add
public int add(byte[] item, int off, int len) throws java.lang.IndexOutOfBoundsExceptionItems 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 classFixedLeafBuilder
- Parameters:
item
- the item's data (copied)off
- starting offset into itemlen
- = 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).
-