search_vec Class Template Reference

#include <search_vec.h>


Detailed Description

template<class vec_t>
class search_vec< vec_t >

Searching class for monotonic data.

A searching class for monotonic vectors. A caching system similar to gsl_interp_accel is used.

For normal usage, just use find(). If you happen to know in advance that the vector is increasing or decreasing, then you can use find_inc() or find_dec() instead.

Todo:
The documentation here is still kind of unclear.

Definition at line 52 of file search_vec.h.


Public Member Functions

size_t find (const double x0, size_t n, const vec_t &x)
 Search an increasing or decreasing vector.
size_t find_inc (const double x0, size_t n, const vec_t &x)
 Search part of a increasing vector.
size_t find_dec (const double x0, size_t n, const vec_t &x)
 Search part of a decreasing vector.
size_t ordered_lookup (const double x0, size_t n, const vec_t &x)
 Find the index of x0 in the ordered array x.
size_t ordered_interval (const double x0, size_t n, const vec_t &x)
 Find the interval containing x0 in the ordered array x.
size_t bsearch_inc (const double x0, const vec_t &x, size_t lo, size_t hi) const
 Binary search a part of an increasing vector.
size_t bsearch_dec (const double x0, const vec_t &x, size_t lo, size_t hi) const
 Binary search a part of an decreasing vector.

Protected Attributes

size_t cache
 Storage for the most recent index.

Member Function Documentation

size_t ordered_lookup ( const double  x0,
size_t  n,
const vec_t &  x 
) [inline]

Find the index of x0 in the ordered array x.

This returns the index i for which x[i] is as close as possible to x0 if x[i] is either increasing or decreasing.

If some of the values in the ovector are not finite, then the output of this function is not defined.

If x[i] is non-monotonic, consider using ovector_view_tlate::lookup() or uvector_view_tlate::lookup() instead of this function.

Definition at line 120 of file search_vec.h.

size_t ordered_interval ( const double  x0,
size_t  n,
const vec_t &  x 
) [inline]

Find the interval containing x0 in the ordered array x.

This returns the index i for which x[i]<=x0<x[i+1].

If the array is increasing and x0<x[0], then 0 is returned. If the array is increasing and x0>x[n-1], then nvar-1 is returned (this behavior is slightly different from GSL). The decreasing case is handled analogously.

If some of the values in the vector are not finite, then the output of this function is not defined.

If x[i] is non-monotonic, consider using ovector_view_tlate::lookup() or uvector_view_tlate::lookup() instead of this function.

Definition at line 167 of file search_vec.h.

size_t bsearch_inc ( const double  x0,
const vec_t &  x,
size_t  lo,
size_t  hi 
) const [inline]

Binary search a part of an increasing vector.

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

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

The cache is not used for this function.

Definition at line 200 of file search_vec.h.

size_t bsearch_dec ( const double  x0,
const vec_t &  x,
size_t  lo,
size_t  hi 
) const [inline]

Binary search a part of an decreasing vector.

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

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

The cache is not used for this function.

Definition at line 226 of file search_vec.h.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page