private int binarySearch ( int position ) { int [ ] minSeqIndex = getMinSequenceIndex ( ) ; int [ ] maxSeqIndex = getMaxSequenceIndex ( ) ; int low = 0 ; int high = minSeqIndex . length - 1 ; while ( low <= high ) { //Go to the mid point in the array int mid = ( low + high ) >>> 1 ; //Get the max position represented by this Sequence int midMinPosition = minSeqIndex [ mid ] ; int midMaxPosition = maxSeqIndex [ mid ] ; //if current position is greater than the current bounds then //increase search space if ( midMinPosition < position && midMaxPosition < position ) { low = mid + 1 ; } //if current position is less than current bounds then decrease //search space else if ( midMinPosition > position && midMaxPosition > position ) { high = mid - 1 ; } else { return mid ; } } throw new IndexOutOfBoundsException ( "Given position " + position + " does not map into this Sequence" ) ; }
Scans through the sequence index arrays using binary search