public final class MerkleTreeUtil extends Object
| Modifier and Type | Method and Description | 
|---|---|
| static Collection<Integer> | compareTrees(com.hazelcast.wan.merkletree.MerkleTreeView local,
            com.hazelcast.wan.merkletree.MerkleTreeView remote)Compares the provided local and the remote Merkle trees and
 returns the breadth-first orders of the leaves that found to be
 different. | 
| static RemoteMerkleTreeView | createRemoteMerkleTreeView(DataInput in)Creates a  RemoteMerkleTreeViewby reading the hashes of
 the leaves of a Merkle tree from the providedDataInput | 
| static int | getLeftChildOrder(int nodeOrder)Returns the breadth-first order of the left child node of the node
 with  nodeOrder | 
| static int | getLevelOfNode(int nodeOrder)Returns the level a node with the given  orderis on in the tree | 
| static int | getNodesOnLevel(int level)Returns the number of nodes on the provided  level | 
| static int | getParentOrder(int nodeOrder)Returns the breadth-first order of the parent node of the node
 with  nodeOrder | 
| static int | getRightChildOrder(int nodeOrder)Returns the breadth-first order of the right child node of the node
 with  nodeOrder | 
| static int | sumHash(int leftHash,
       int rightHash)Sums the hash of the left and the right children | 
| static void | writeLeaves(DataOutput out,
           com.hazelcast.wan.merkletree.MerkleTreeView merkleTreeView)Writes the hashes of the leaves of a Merkle tree into the
 provided  DataOutput | 
public static int sumHash(int leftHash,
                          int rightHash)
May be used only when calculating a non-leaf node's hash code from its children's hashes.
leftHash - The hash of the left childrightHash - The hash of the right childaddHash(int, int), 
removeHash(int, int)public static int getLevelOfNode(int nodeOrder)
order is on in the treenodeOrder - The breadth-first order of a node for which its level
                  to be calculatedorder is onpublic static int getNodesOnLevel(int level)
levellevel - The levelpublic static int getParentOrder(int nodeOrder)
nodeOrdernodeOrder - The order of the node for which its parent's order
                  to be calculatedpublic static int getLeftChildOrder(int nodeOrder)
nodeOrdernodeOrder - The order of the node for which its left child's
                  order to be calculatedpublic static int getRightChildOrder(int nodeOrder)
nodeOrdernodeOrder - The order of the node for which its right child's
                  order to be calculatedpublic static Collection<Integer> compareTrees(com.hazelcast.wan.merkletree.MerkleTreeView local, com.hazelcast.wan.merkletree.MerkleTreeView remote)
This method compares only the leaves instead of traversing only the subtrees that are different. This way possible hash collisions inside the tree don't remain hidden and then syncing the clusters can be initiated. This comes at the cost of comparing every leaf at every comparison.
local - The view of the local Merkle treeremote - The view of the remote Merkle treepublic static void writeLeaves(DataOutput out, com.hazelcast.wan.merkletree.MerkleTreeView merkleTreeView) throws IOException
DataOutputout - The data output to write the leaves intomerkleTreeView - The Merkle tree which leaves to be written
                       into the data outputIOException - if an I/O error occurspublic static RemoteMerkleTreeView createRemoteMerkleTreeView(DataInput in) throws IOException
RemoteMerkleTreeView by reading the hashes of
 the leaves of a Merkle tree from the provided DataInputin - The data input the hashes to be read fromIOException - if an I/O error occursCopyright © 2022 Hazelcast, Inc.. All Rights Reserved.