private int binarySearch ( List < SparseItemset > candidates , SparseItemset scratch , int begin , int end ) { -- end ; while ( begin < end ) { final int mid = ( begin + end ) >>> 1 ; SparseItemset midVal = candidates . get ( mid ) ; int cmp = midVal . compareTo ( scratch ) ; if ( cmp < 0 ) { begin = mid + 1 ; } else if ( cmp > 0 ) { end = mid - 1 ; } else { return mid ; // key found } } return - ( begin + 1 ) ; // key not found, return next }
Binary - search for the next - larger element .