This is a utility function which searches an ordered monotonic sequence and returns the relative position within the sequence using a method which combines the hunt and Bisection method.
public int HuntBisectionLocate( double[]monotonicSequence, doublevalueBeingOrdered );
Parameters
monotonicSequence
An array of monotonic values (increasing or decreasing).
valueBeingOrdered
Value to the point which is being given a relative ordering.
Remarks
This method first finds (or hunts for) two elements of a sequence of
monotonic real numbers (i.e. sequentially increasing or decreasing)
which bracket the desired value and then applies in bisection searching
algorithm.
This method attempts to bracket the valueBeingOrdered
parameter between two consecutive elements of the array and return
the lower bound. Several special cases are treated separately as follows:
If the array is null, an InterpolationException is thrown.
If the array is empty, this method will always return zero.
If the value being ordered equals the first elements within the
array, this method will always return the position of the first element.
If the value being ordered equals all elements within the
array, this method will always return the position of the first element.
If the value being ordered equals the last elements within the
array, this method will always return the position of the penultimate
element, unless one of the previous situations occurs.
If the value being ordered equals consecutive elements inside the
array, located neither at the beginning or end of the array, this
method will return the position of the last consecutive element for
an array of increasing values or the position of the element before
the first consecutive element for an array of decreasing values.
If the value being ordered is outside the range of the array,
this method will either return -1 if the value should be
ordered before the first element or the position of the last element
if the value should be ordered after the last element.