Package io.crums.util.mrkl
Class Tree
java.lang.Object
io.crums.util.mrkl.Tree
- Direct Known Subclasses:
 DeltaTree,FixedLeafTree,FreeLeafTree
public abstract class Tree
extends java.lang.Object
The Merkle tree. Instances are immutable. This class abstracts away the
 memory layout for the tree.
- See Also:
 Builder,FixedLeafTree,FreeLeafTree
- 
Field Summary
Fields Modifier and Type Field Description static byteBRANCH_PADstatic byteLEAF_PAD - 
Constructor Summary
 - 
Method Summary
Modifier and Type Method Description protected java.lang.StringBuilderappendToStringDetail(java.lang.StringBuilder string)abstract byte[]data(int level, int index)Returns [a copy of] the data for the node at the specified coordinates.java.lang.StringgetHashAlgo()byte[]hash()Returns the hash of the root of the tree.inthashAlgoWidth()Returns the byte width of the hashing algorithm by observing the width of the node at coordinates (1, 0), which is the first internal node constructed in a tree.static byte[]hashInternals(byte[] left, byte[] right, java.security.MessageDigest digest)static byte[]hashLeaves(byte[] left, byte[] right, java.security.MessageDigest digest)static byte[]hashUncommon(byte[] leftInternal, byte[] rightLeaf, java.security.MessageDigest digest)TreeIndex<Node>idx()Returns the random access index into tree structure.booleanisLeafWidthFixed()Determines whether the width of the leaves is fixed.booleanisOmniWidth()Determines whether the width of the leaves is the same as the byte width of the hashing algorithm.abstract intleafWidth()Returns the leaf width in bytes if fixed; -1, otherwise (variable).Proofproof(int leafIndex)Returns a cryptographic path to the root of the Merkle tree.Noderoot()Returns the root node of the tree.java.lang.StringtoString()For debug use.booleanverify(Node node, java.security.MessageDigest digest)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
- 
Field Details
- 
LEAF_PAD
public static final byte LEAF_PAD- See Also:
 - Constant Field Values
 
 - 
BRANCH_PAD
public static final byte BRANCH_PAD- See Also:
 - Constant Field Values
 
 
 - 
 - 
Constructor Details
- 
Tree
protected Tree(int leaves, java.lang.String algo)Base constructor creates an index and locks down the algo.- Parameters:
 leaves- the number of leaf nodes in the treealgo- the hash algo used for the trees internal nodes.
 - 
Tree
Copy constructor. 
 - 
 - 
Method Details
- 
hashLeaves
public static byte[] hashLeaves(byte[] left, byte[] right, java.security.MessageDigest digest) - 
hashInternals
public static byte[] hashInternals(byte[] left, byte[] right, java.security.MessageDigest digest) - 
hashUncommon
public static byte[] hashUncommon(byte[] leftInternal, byte[] rightLeaf, java.security.MessageDigest digest) - 
root
Returns the root node of the tree.- See Also:
 hash()
 - 
hash
public final byte[] hash()Returns the hash of the root of the tree. - 
getHashAlgo
public final java.lang.String getHashAlgo() - 
idx
Returns the random access index into tree structure. - 
verify
 - 
data
public abstract byte[] data(int level, int index)Returns [a copy of] the data for the node at the specified coordinates.- See Also:
 Node.data(),#data(int, int, ByteBuffer)
 - 
leafWidth
public abstract int leafWidth()Returns the leaf width in bytes if fixed; -1, otherwise (variable). - 
isLeafWidthFixed
public final boolean isLeafWidthFixed()Determines whether the width of the leaves is fixed.- Returns:
 - true iff the leaf width is not variable
 
 - 
isOmniWidth
public final boolean isOmniWidth()Determines whether the width of the leaves is the same as the byte width of the hashing algorithm. - 
hashAlgoWidth
public final int hashAlgoWidth()Returns the byte width of the hashing algorithm by observing the width of the node at coordinates (1, 0), which is the first internal node constructed in a tree. - 
proof
Returns a cryptographic path to the root of the Merkle tree. - 
toString
public java.lang.String toString()For debug use.- Overrides:
 toStringin classjava.lang.Object
 - 
appendToStringDetail
protected java.lang.StringBuilder appendToStringDetail(java.lang.StringBuilder string) 
 -