protected void hunt ( float val ) { int lowerLimit = center ; int upperLimit ; int inc = 1 ; if ( val >= x [ lowerLimit ] && ascend ) { // hunt up for ( ; ; ) { upperLimit = lowerLimit + inc ; // see if it is outside the table if ( upperLimit >= size - 1 ) { upperLimit = size - 1 ; break ; } else if ( val < x [ upperLimit ] && ascend ) { break ; } else { lowerLimit = upperLimit ; inc += inc ; } } } else { // hunt down upperLimit = lowerLimit ; for ( ; ; ) { lowerLimit = lowerLimit - inc ; if ( lowerLimit <= 0 ) { lowerLimit = 0 ; break ; } else if ( val >= x [ lowerLimit ] && ascend ) { break ; } else { upperLimit = lowerLimit ; inc += inc ; } } } bisectionSearch ( val , lowerLimit , upperLimit ) ; }
To speed up finding the appropriate indexes to use in the interpolation it can use its previous results to search a smaller region than it would otherwise .