23 #ifndef O2SCL_SEARCH_VEC_H 24 #define O2SCL_SEARCH_VEC_H 33 #include <o2scl/err_hnd.h> 34 #include <o2scl/vector.h> 36 #ifndef DOXYGEN_NO_O2NS 81 #ifndef DOXYGEN_INTERNAL 111 std::string str=((std::string)
"Vector too small (size=")+
122 std::string str=((std::string)
"Vector too small (size=")+
137 size_t find(
const double x0)
const {
138 #if !O2SCL_NO_RANGE_CHECK 140 O2SCL_ERR(
"Cache mis-alignment in search_vec::find().",
144 if ((*v)[0]<(*v)[n-1])
return find_inc(x0);
158 if (x0<(*v)[cache]) {
159 cache=vector_bsearch_inc<vec_t,double>(x0,*
v,0,
cache);
160 }
else if (x0>=(*v)[cache+1]) {
161 cache=vector_bsearch_inc<vec_t,double>(x0,*
v,
cache,n-1);
163 #if !O2SCL_NO_RANGE_CHECK 165 O2SCL_ERR(
"Cache mis-alignment in search_vec::find_inc().",
181 if (x0>(*v)[cache]) {
182 cache=vector_bsearch_dec<vec_t,double>(x0,*
v,0,
cache);
183 }
else if (x0<=(*v)[cache+1]) {
184 cache=vector_bsearch_dec<vec_t,double>(x0,*
v,
cache,n-1);
186 #if !O2SCL_NO_RANGE_CHECK 188 O2SCL_ERR(
"Cache mis-alignment in search_vec::find_dec().",
214 std::string str=((std::string)
"Not enough data (n=")+
221 if ((*v)[0]<=(*v)[n-1]) {
229 if (row<n-1 && fabs((*v)[row+1]-x0)<fabs((*v)[row]-x0)) row++;
240 if (row<n-1 && fabs((*v)[row+1]-x0)<fabs((*v)[row]-x0)) row++;
247 #ifndef DOXYGEN_INTERNAL 263 #ifndef DOXYGEN_INTERNAL 303 std::string str=((std::string)
"Vector too small (n=")+
313 size_t find(
const double x0)
const {
314 #if !O2SCL_NO_RANGE_CHECK 315 if (this->cache>=this->n) {
316 O2SCL_ERR(
"Cache mis-alignment in search_vec_ext::find().",
320 if ((*this->v)[0]<(*this->v)[this->n-1])
return find_inc(x0);
328 if (x0<(*this->v)[this->cache]) {
329 this->cache=vector_bsearch_inc<vec_t,double>
330 (x0,*this->
v,0,this->
cache);
331 }
else if (this->cache<this->n-1 && x0>=(*this->v)[this->cache+1]) {
332 this->cache=vector_bsearch_inc<vec_t,double>
333 (x0,*this->
v,this->
cache,this->
n);
335 #if !O2SCL_NO_RANGE_CHECK 336 if (this->cache>=this->n) {
337 O2SCL_ERR(
"Cache mis-alignment in search_vec_ext::find_inc().",
348 if (x0>(*this->v)[this->cache]) {
349 this->cache=vector_bsearch_dec<vec_t,double>
350 (x0,*this->
v,0,this->
cache);
351 }
else if (this->cache<this->n-1 && x0<=(*this->v)[this->cache+1]) {
352 this->cache=vector_bsearch_dec<vec_t,double>
353 (x0,*this->
v,this->
cache,this->
n);
355 #if !O2SCL_NO_RANGE_CHECK 356 if (this->cache>=this->n) {
357 O2SCL_ERR(
"Cache mis-alignment in search_vec_ext::find_dec().",
364 #ifndef DOXYGEN_INTERNAL 375 #ifndef DOXYGEN_NO_O2NS size_t cache
Storage for the most recent index.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
sanity check failed - shouldn't happen
invalid argument supplied by user
search_vec_ext()
Create a blank searching object.
size_t cache
Storage for the most recent index.
size_t find_inc(const double x0) const
Search an increasing vector for the interval containing x0
search_vec()
Create a blank searching object.
search_vec(size_t nn, const vec_t &x)
Create a searching object with vector x of size nn.
size_t find(const double x0) const
Search an increasing or decreasing vector for the interval containing x0
const vec_t * v
The vector to be searched.
size_t find_dec(const double x0) const
Search a decreasing vector for the interval containing x0
size_t find(const double x0) const
Search an increasing or decreasing vector for the interval containing x0
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
size_t ordered_lookup(const double x0) const
Find the index of x0 in the ordered array x.
size_t find_dec(const double x0) const
Search a decreasing vector for the interval containing x0
size_t find_inc(const double x0) const
Search an increasing vector for the interval containing x0
Searching class for monotonic data with caching.
An extended search_vec which is allowed to return the last element.
void set_vec(size_t nn, const vec_t &x)
Set the vector to be searched.
search_vec_ext(size_t nn, const vec_t &x)
Create a searching object for vector x of size nn.
const vec_t * v
The vector to be searched.
std::string szttos(size_t x)
Convert a size_t to a string.