public class MerkleTree<K extends IByteable> extends Object implements IMerkleTree<K>
| Constructor and Description |
|---|
MerkleTree() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(K entry)
Add or update the entry to/in the tree.
|
boolean |
contains(K key)
Check if an entry is already present
|
protected MerkleNode<K> |
createNode(K entry) |
KeyIndex<K> |
get(int index) |
K |
get(K entry)
Return an entry from the tree, uses
Object.equals(Object) for equality-checks |
HashWithCount |
getHashWithCount() |
int |
getHeight() |
MerkleNode<K> |
getRoot() |
byte[] |
getRootHash() |
boolean |
iterateNodes(IterateFunction<K> function)
Iterate over every node.
|
RemoveResult<K> |
remove(K key)
Remove an entry from the tree
|
int |
size() |
String |
toPrettyString() |
public int size()
size in interface IMerkleTree<K extends IByteable>public int getHeight()
getHeight in interface IMerkleTree<K extends IByteable>public boolean contains(K key)
IMerkleTreecontains in interface IMerkleTree<K extends IByteable>key - the Entry to search for in this tree. Should not be nullpublic K get(K entry)
IMerkleTreeObject.equals(Object) for equality-checksget in interface IMerkleTree<K extends IByteable>entry - a non-null entry to lookup in the treepublic KeyIndex<K> get(int index)
get in interface IMerkleTree<K extends IByteable>index - the index of the node where the entry should be retrievedpublic boolean add(K entry)
IMerkleTreeadd in interface IMerkleTree<K extends IByteable>entry - the non-null entry to addpublic RemoveResult<K> remove(K key)
IMerkleTreeremove in interface IMerkleTree<K extends IByteable>key - the entry to removepublic HashWithCount getHashWithCount()
getHashWithCount in interface IMerkleTree<K extends IByteable>public byte[] getRootHash()
getRootHash in interface IMerkleTree<K extends IByteable>public MerkleNode<K> getRoot()
getRoot in interface IMerkleTree<K extends IByteable>public String toPrettyString()
toPrettyString in interface IMerkleTree<K extends IByteable>public boolean iterateNodes(IterateFunction<K> function)
IMerkleTreeiterateNodes in interface IMerkleTree<K extends IByteable>function - a IterateFunction that should be executed for nodefalse when nothing has been iterated. true when iteration ended after at least one leafprotected MerkleNode<K> createNode(K entry)
Copyright © 2018. All rights reserved.