private boolean findFirstSorted ( RowCursor minCursor , RowCursor resultCursor , boolean isMatch ) { int rowOffset = _rowSortHead ; int rowLength = resultCursor . length ( ) ; int cmp = resultCursor . compareKey ( _keyMinSort , 0 ) ; if ( cmp < 0 || cmp == 0 && isMatch ) { return isMatch ; } int minCmp = minCursor . compareKey ( _keyMaxSort , 0 ) ; if ( minCmp > 0 ) { return isMatch ; } minCmp = minCursor . compareKey ( _keyMinSort , 0 ) ; if ( minCmp <= 0 ) { fillMatch ( BLOCK_SIZE - rowLength , resultCursor ) ; return true ; } int length = ( BLOCK_SIZE - rowOffset ) / rowLength - 1 ; // rowOffset += rowLength; while ( length > 0 ) { int pivot = length / 2 ; int pivotOffset = rowOffset + pivot * rowLength ; // if minCursor is in this block, test if the row is greater minCmp = minCursor . compareKeyRow ( _buffer , pivotOffset ) ; if ( minCmp == 0 ) { return fillMatch ( pivotOffset , resultCursor ) ; } else if ( minCmp > 0 ) { length = pivot ; continue ; } // test row against current min cmp = resultCursor . compareKeyRow ( _buffer , pivotOffset ) ; if ( cmp > 0 ) { // it's a better result, copy and search for smaller isMatch = true ; fillMatch ( pivotOffset , resultCursor ) ; } // search for smaller rowOffset = pivotOffset + rowLength ; length = length - pivot - 1 ; } return isMatch ; }
In a sorted block find the minimum key less than the currentResult and greater than the min .