src/java/org/apache/cassandra/utils/MerkleTree.java
/**
     * TODO: This function could be optimized into a depth first traversal of
     * the two trees in parallel.
     *
     * Takes two trees and a range for which they have hashes, but are inconsistent.
     * @return FULLY_INCONSISTENT if active is inconsistent, PARTIALLY_INCONSISTENT if only a subrange is inconsistent.
     */
This function could be optimized into a depth first traversal of
the two trees in parallel.

Takes two trees and a range for which they have hashes, but are inconsistent.
@return FULLY_INCONSISTENT if active is inconsistent, PARTIALLY_INCONSISTENT if only a subrange is inconsistent.
This function could be optimized into a depth first traversal of the two trees in parallel . Takes two trees and a range for which they have hashes but are inconsistent . @return FULLY_INCONSISTENT if active is inconsistent PARTIALLY_INCONSISTENT if only a subrange is inconsistent .
static int differenceHelper(MerkleTree ltree, MerkleTree rtree, List<TreeRange> diff, TreeRange active)
    {
        Token midpoint = ltree.partitioner().midpoint(active.left, active.right);
        TreeRange left = new TreeRange(null, active.left, midpoint, inc(active.depth), null);
        TreeRange right = new TreeRange(null, midpoint, active.right, inc(active.depth), null);
        byte[] lhash;
        byte[] rhash;
        lhash = ltree.hash(left);
        rhash = rtree.hash(left);
        int ldiff = CONSISTENT;
        boolean lreso = lhash != null && rhash != null;
        if (lreso && !Arrays.equals(lhash, rhash))
            ldiff = differenceHelper(ltree, rtree, diff, left);
        else if (!lreso)
            ldiff = FULLY_INCONSISTENT;
        lhash = ltree.hash(right);
        rhash = rtree.hash(right);
        int rdiff = CONSISTENT;
        boolean rreso = lhash != null && rhash != null;
        if (rreso && !Arrays.equals(lhash, rhash))
            rdiff = differenceHelper(ltree, rtree, diff, right);
        else if (!rreso)
            rdiff = FULLY_INCONSISTENT;
        if (ldiff == FULLY_INCONSISTENT && rdiff == FULLY_INCONSISTENT)
        {
            return FULLY_INCONSISTENT;
        }
        else if (ldiff == FULLY_INCONSISTENT)
        {
            diff.add(left);
            return PARTIALLY_INCONSISTENT;
        }
        else if (rdiff == FULLY_INCONSISTENT)
        {
            diff.add(right);
            return PARTIALLY_INCONSISTENT;
        }
        return PARTIALLY_INCONSISTENT;
    }
static int differenceHelper ( MerkleTree ltree , MerkleTree rtree , List < TreeRange > diff , TreeRange active ) { Token midpoint = ltree . partitioner ( ) . midpoint ( active . left , active . right ) ; TreeRange left = new TreeRange ( null , active . left , midpoint , inc ( active . depth ) , null ) ; TreeRange right = new TreeRange ( null , midpoint , active . right , inc ( active . depth ) , null ) ; byte [ ] lhash ; byte [ ] rhash ; lhash = ltree . hash ( left ) ; rhash = rtree . hash ( left ) ; int ldiff = CONSISTENT ; boolean lreso = lhash != null && rhash != null ; if ( lreso && ! Arrays . equals ( lhash , rhash ) ) ldiff = differenceHelper ( ltree , rtree , diff , left ) ; else if ( ! lreso ) ldiff = FULLY_INCONSISTENT ; lhash = ltree . hash ( right ) ; rhash = rtree . hash ( right ) ; int rdiff = CONSISTENT ; boolean rreso = lhash != null && rhash != null ; if ( rreso && ! Arrays . equals ( lhash , rhash ) ) rdiff = differenceHelper ( ltree , rtree , diff , right ) ; else if ( ! rreso ) rdiff = FULLY_INCONSISTENT ; if ( ldiff == FULLY_INCONSISTENT && rdiff == FULLY_INCONSISTENT ) { return FULLY_INCONSISTENT ; } else if ( ldiff == FULLY_INCONSISTENT ) { diff . add ( left ) ; return PARTIALLY_INCONSISTENT ; } else if ( rdiff == FULLY_INCONSISTENT ) { diff . add ( right ) ; return PARTIALLY_INCONSISTENT ; } return PARTIALLY_INCONSISTENT ; }
TODO: This function could be optimized into a depth first traversal of
 the two trees in parallel.
TODO : This function could be optimized into a depth first traversal of the two trees in parallel .
// see if we should recurse left // see if we should recurse right // both children are fully inconsistent