private int findChild ( L child , float depth ) { // findInsertion will find us some element with the same depth as the to-be-removed child int startIdx = findInsertion ( depth ) ; // search down for our child for ( int ii = startIdx - 1 ; ii >= 0 ; ii -- ) { L c = children . get ( ii ) ; if ( c == child ) { return ii ; } if ( c . depth ( ) != depth ) { break ; } } // search up for our child for ( int ii = startIdx , ll = children . size ( ) ; ii < ll ; ii ++ ) { L c = children . get ( ii ) ; if ( c == child ) { return ii ; } if ( c . depth ( ) != depth ) { break ; } } return - 1 ; }
uses depth to improve upon a full linear search