Class DeltaBuilder
java.lang.Object
io.crums.util.mrkl.Builder
io.crums.util.mrkl.FixedLeafBuilder
io.crums.util.mrkl.DeltaBuilder
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:
-
Field Summary
Fields inherited from class io.crums.util.mrkl.Builder
copyOnWrite, data, digest, lock -
Constructor Summary
ConstructorsConstructorDescriptionDeltaBuilder(Tree tree) Constructs a copy-on-write instance.DeltaBuilder(Tree tree, boolean copyOnWrite) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionintadd(byte[] item, int off, int len) Items only the width of the (hash) digest width are allowed because this is an omni-width tree.build()Builds and returns the tree.voidclear()Clears the state of the instance, as if new.intReturns the total number of items added (appended).protected DeltaTreeMethods inherited from class io.crums.util.mrkl.FixedLeafBuilder
leafWidthMethods inherited from class io.crums.util.mrkl.Builder
add, completeTree, count, getHashAlgo, hash, hashWidth, item, level, levelSize, newByteArrayList
-
Constructor Details
-
DeltaBuilder
Constructs a copy-on-write instance.- Parameters:
tree- the base tree to start from- See Also:
-
DeltaBuilder
Creates a new instance.- Parameters:
tree- the base tree to start fromcopyOnWrite- iftrue, 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 tofalse
-
-
Method Details
-
build
Description copied from class:BuilderBuilds and returns the tree. On return the builder is cleared.- Overrides:
buildin classFixedLeafBuilder- See Also:
-
packageTree
- Overrides:
packageTreein classFixedLeafBuilder
-
clear
-
add
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:
addin classFixedLeafBuilder- Parameters:
item- the item's data (copied)off- starting offset intoitemlen- = FixedLeafBuilder.leafWidth()- Returns:
- the item's leaf node index in the to-be built tree
- Throws:
IndexOutOfBoundsException
-
itemsAdded
public int itemsAdded()Returns the total number of items added (appended).
-