Class FixedLeafTree
java.lang.Object
io.crums.util.mrkl.Tree
io.crums.util.mrkl.FixedLeafTree
A more compact
Tree appropriate if the leaves are fixed-width
and it'all fits under 2 gigabytes.- See Also:
-
Field Summary
FieldsFields inherited from class io.crums.util.mrkl.Tree
BRANCH_PAD, LEAF_PAD -
Constructor Summary
ConstructorsModifierConstructorDescriptionFixedLeafTree(int leaves, String algo, byte[] data, int algoWidth, int leafWidth) Creates a new instance.protectedFixedLeafTree(FixedLeafTree copy) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]data(int level, int index) Returns [a copy of] the data for the node at the specified coordinates.Returns entire data block.protected ByteBufferReturns the data beyond the standard definition of the tree.static booleanfitsModelCapacity(int leaves, int algoWidth, int leafWidth) intintReturns the fixed-size leaf width.Returns the leaves' data block.static inttreeDataLength(int leaves, int algoWidth, int leafWidth) Returns the number of bytes needed to encode the state of the tree, or -1 if that number exceeds the maximumintJava allows.Methods inherited from class io.crums.util.mrkl.Tree
appendToStringDetail, getHashAlgo, hash, hashAlgoWidth, hashInternals, hashInternals, hashLeaves, hashLeaves, hashUncommon, hashUncommon, idx, isLeafWidthFixed, isOmniWidth, proof, root, toString
-
Field Details
-
MIN_ALGO_WIDTH
public static final int MIN_ALGO_WIDTH- See Also:
-
MIN_LEAF_WIDTH
public static final int MIN_LEAF_WIDTH- See Also:
-
-
Constructor Details
-
FixedLeafTree
public FixedLeafTree(int leaves, String algo, byte[] data, int algoWidth, int leafWidth) throws IllegalArgumentException Creates a new instance.- Parameters:
leaves- number of leaf nodes in the treealgo- hash algo used for the trees internal nodesdata- node data in serial form (interpreted by next parameters)algoWidth- number of bytes in the hash generated byalgoleafWidth- number of bytes in a leaf node- Throws:
IllegalArgumentException
-
FixedLeafTree
Copy constructor.
-
-
Method Details
-
data
public byte[] data(int level, int index) Description copied from class:TreeReturns [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. -
leafWidth
-
dataBlock
Returns entire data block.- Returns:
- a new read-only view of the entire block.
-
leavesBlock
Returns the leaves' data block.- Returns:
- a new read-only view of leaves' block.
-
extraBlock
Returns the data beyond the standard definition of the tree. This is a view of whatever bytes remain in the data block after the tree definition.- Returns:
- possibly empty extra block
-
hashWidth
public int hashWidth() -
fitsModelCapacity
public static boolean fitsModelCapacity(int leaves, int algoWidth, int leafWidth) -
treeDataLength
public static int treeDataLength(int leaves, int algoWidth, int leafWidth) Returns the number of bytes needed to encode the state of the tree, or -1 if that number exceeds the maximumintJava allows.
-