Function vector_bsearch_dec (o2scl)

O2scl : Function List

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

Binary search a part of an decreasing vector for x0.

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

  • lo if x0 > x[lo]

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

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

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.

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.