cxbsearch.h File Reference

#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.

Detailed Description


Function Documentation

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.


Distributed by BN Algorithms Ltd -- consulting in quantitative finance, mathematical algorithms and software implementations. CDS Home Page. For enquires contact webs@bnikolic.co.uk.
This documentation is derived from ISDA CDS Standard Model version 1.7. You can get a copy of the original ISDA code at www.bnikolic.co.uk. This is a derivative work under the terms of the ISDA CDS Standard Model Public License. BN Algorithms Ltd licenses this work to you solely for on-screen viewing on your own computer. Making copies and further distribution of this work is prohibited.
This documentation is provided "as-is", without warranty of any kind, either expressed or implied, including, without limitation, warranties that the documentation is free of defects, merchantable, fit for a particular purpose or non-infringing. the entire risk as to the quality of the documentation is with you. Should this documentation prove defective in any respect, you (not the licensor) assume the cost of any necessary correction. This disclaimer of warranty constitutes an essential part of this license.