src/java/org/apache/cassandra/utils/MerkleTree.java
/**
     * @throws StopRecursion If no match could be found for the range.
     */
@throws StopRecursion If no match could be found for the range.
@throws StopRecursion If no match could be found for the range .
private byte[] hashHelper(Hashable hashable, Range<Token> active, Range<Token> range) throws StopRecursion
    {
        if (hashable instanceof Leaf)
        {
            if (!range.contains(active))
                throw new StopRecursion.BadRange();
            return hashable.hash();
        }
        Inner node = (Inner)hashable;
        Range<Token> leftactive = new Range<Token>(active.left, node.token);
        Range<Token> rightactive = new Range<Token>(node.token, active.right);
        if (range.contains(active))
        {
            if (node.hash() != null)
                return node.hash();
            byte[] lhash = hashHelper(node.lchild(), leftactive, range);
            byte[] rhash = hashHelper(node.rchild(), rightactive, range);
            node.hash(lhash, rhash);
            return node.hash();
        } 
        if (leftactive.contains(range))
            return hashHelper(node.lchild, leftactive, range);
        else if (rightactive.contains(range))
            return hashHelper(node.rchild, rightactive, range);
        else
            throw new StopRecursion.BadRange();
    }
private byte [ ] hashHelper ( Hashable hashable , Range < Token > active , Range < Token > range ) throws StopRecursion { if ( hashable instanceof Leaf ) { if ( ! range . contains ( active ) ) throw new StopRecursion . BadRange ( ) ; return hashable . hash ( ) ; } Inner node = ( Inner ) hashable ; Range < Token > leftactive = new Range < Token > ( active . left , node . token ) ; Range < Token > rightactive = new Range < Token > ( node . token , active . right ) ; if ( range . contains ( active ) ) { if ( node . hash ( ) != null ) return node . hash ( ) ; byte [ ] lhash = hashHelper ( node . lchild ( ) , leftactive , range ) ; byte [ ] rhash = hashHelper ( node . rchild ( ) , rightactive , range ) ; node . hash ( lhash , rhash ) ; return node . hash ( ) ; } if ( leftactive . contains ( range ) ) return hashHelper ( node . lchild , leftactive , range ) ; else if ( rightactive . contains ( range ) ) return hashHelper ( node . rchild , rightactive , range ) ; else throw new StopRecursion . BadRange ( ) ; }
@throws StopRecursion If no match could be found for the range.
@throws StopRecursion If no match could be found for the range .
// we are not fully contained in this range! // else: node. // this node is fully contained in the range // we had a cached value // continue recursing to hash our children // cache the computed value (even if it is null) // else: one of our children contains the range // left child contains/matches the range // right child contains/matches the range