#include <stdlib.h>
Functions | |
int | JpmcdsBinarySearchLong (long xDesired, long *xArray, size_t skip, long arraySize, long *exact, long *loBound, long *hiBound) |
Searches for a long value within an array. |
int JpmcdsBinarySearchLong | ( | long | xDesired, | |
long * | xArray, | |||
size_t | skip, | |||
long | arraySize, | |||
long * | exact, | |||
long * | loBound, | |||
long * | hiBound | |||
) |
Searches for a long value within an array.
The array can either be an array of longs, or else an array of something bigger than a long which has one of its elements equal to the value that we seek.
Returns three values - the exact value (if it exists), the lower bound and the upper bound.
The lower bound is defined as the index of the last value which is strictly less than the desired value.
The upper bound is defined as the index of the first value which is strictly greater than the desired value.
The exact value is the index of a value which is equal to the desired value.
In the case that such an index cannot be found, then the value of -1 is returned for exact and loBound, and arraySize for hiBound.
The idea behind these return values is that hiBound-loBound-1 should give the number of exact matches in all cases, and that everything in the range [loBound+1, hiBound-1] inclusive should be an exact match.
If the input array is not sorted in ascending order, then the output is undefined. No checks are performed on the order of xArray - this would in fact defeat the purpose of having a fast binary search if you are going to slow it down by doing a linear check of the inputs.