Function vector_bsearch_inc (o2scl)

O2scl : Function List

template<class vec_t, class data_t>
size_t o2scl::vector_bsearch_inc(const data_t x0, const vec_t &x, size_t lo, size_t hi)

Binary search a part of an increasing vector for x0.

This function performs a binary search of between x[lo] and x[hi]. It returns

  • lo if x0 < x[lo]

  • i if x[i] <= x0 < x[i+2] for lo <= i < hi

  • hi-1 if x0 >= [hi-1]

This function is designed to find the interval containing x0, not the index of the element closest to x0. To perform the latter operation, you can use vector_lookup().

The element at x[hi] is never referenced by this function. The parameter hi can be either the index of the last element (e.g. n-1 for a vector of size n with starting index 0), or the index of one element (e.g. n for a vector of size n and a starting index 0) for a depending on whether or not the user wants to allow the function to return the index of the last element.

This function operates in the same way as gsl_interp_bsearch().

The operation of this function is undefined if the data is not strictly monotonic, i.e. if some of the data elements are equal.

This function will call the error handler if lo is greater than hi.