#include <search_vec.h>
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.
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. |
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 168 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.
The cache is not used for this function.
Definition at line 194 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.
The cache is not used for this function.
Definition at line 212 of file search_vec.h.
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page