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
76 #ifndef DOXYGEN_INTERNAL
99 std::string str=((std::string)
"Vector too small (size=")+
109 std::string str=((std::string)
"Vector too small (size=")+
125 #if !O2SCL_NO_RANGE_CHECK
127 O2SCL_ERR(
"Cache mis-alignment in search_vec::find().",
135 size_t find_const(
const double x0,
size_t &cache)
const {
136 #if !O2SCL_NO_RANGE_CHECK
138 O2SCL_ERR(
"Cache mis-alignment in search_vec::find().",
142 if ((*
v)[0]<(*
v)[
n-1])
return find_inc_const(x0,cache);
143 return find_dec_const(x0,cache);
157 if (x0<(*
v)[cache]) {
158 cache=vector_bsearch_inc<vec_t,double>(x0,*
v,0,cache);
159 }
else if (x0>=(*
v)[cache+1]) {
160 cache=vector_bsearch_inc<vec_t,double>(x0,*
v,cache,
n-1);
162 #if !O2SCL_NO_RANGE_CHECK
164 O2SCL_ERR(
"Cache mis-alignment in search_vec::find_inc().",
171 size_t find_inc_const(
const double x0,
size_t &cache)
const {
172 if (x0<(*
v)[cache]) {
173 cache=vector_bsearch_inc<vec_t,double>(x0,*
v,0,cache);
174 }
else if (x0>=(*
v)[cache+1]) {
175 cache=vector_bsearch_inc<vec_t,double>(x0,*
v,cache,
n-1);
177 #if !O2SCL_NO_RANGE_CHECK
179 O2SCL_ERR(
"Cache mis-alignment in search_vec::find_inc().",
196 if (x0>(*
v)[cache]) {
197 cache=vector_bsearch_dec<vec_t,double>(x0,*
v,0,cache);
198 }
else if (x0<=(*
v)[cache+1]) {
199 cache=vector_bsearch_dec<vec_t,double>(x0,*
v,cache,
n-1);
201 #if !O2SCL_NO_RANGE_CHECK
203 O2SCL_ERR(
"Cache mis-alignment in search_vec::find_dec().",
210 size_t find_dec_const(
const double x0,
size_t &cache)
const {
211 if (x0>(*
v)[cache]) {
212 cache=vector_bsearch_dec<vec_t,double>(x0,*
v,0,cache);
213 }
else if (x0<=(*
v)[cache+1]) {
214 cache=vector_bsearch_dec<vec_t,double>(x0,*
v,cache,
n-1);
216 #if !O2SCL_NO_RANGE_CHECK
218 O2SCL_ERR(
"Cache mis-alignment in search_vec::find_dec().",
244 std::string str=((std::string)
"Not enough data (n=")+
251 if ((*
v)[0]<=(*
v)[
n-1]) {
259 row=find_inc_const(x0,cache);
260 if (row<
n-1 && fabs((*
v)[row+1]-x0)<fabs((*
v)[row]-x0)) row++;
271 row=find_dec_const(x0,cache);
272 if (row<
n-1 && fabs((*
v)[row+1]-x0)<fabs((*
v)[row]-x0)) row++;
279 #ifndef DOXYGEN_INTERNAL
295 #ifndef DOXYGEN_INTERNAL
332 std::string str=((std::string)
"Vector too small (n=")+
342 #if !O2SCL_NO_RANGE_CHECK
343 if (this->cache>=this->n) {
344 O2SCL_ERR(
"Cache mis-alignment in search_vec_ext::find().",
348 if ((*this->v)[0]<(*this->v)[this->n-1])
return find_inc(x0);
356 if (x0<(*this->v)[this->cache]) {
357 this->cache=vector_bsearch_inc<vec_t,double>
358 (x0,*this->v,0,this->cache);
359 }
else if (this->cache<this->
n-1 && x0>=(*this->v)[this->cache+1]) {
360 this->cache=vector_bsearch_inc<vec_t,double>
361 (x0,*this->v,this->cache,this->n);
363 #if !O2SCL_NO_RANGE_CHECK
364 if (this->cache>=this->n) {
365 O2SCL_ERR(
"Cache mis-alignment in search_vec_ext::find_inc().",
376 if (x0>(*this->v)[this->cache]) {
377 this->cache=vector_bsearch_dec<vec_t,double>
378 (x0,*this->v,0,this->cache);
379 }
else if (this->cache<this->
n-1 && x0<=(*this->v)[this->cache+1]) {
380 this->cache=vector_bsearch_dec<vec_t,double>
381 (x0,*this->v,this->cache,this->n);
383 #if !O2SCL_NO_RANGE_CHECK
384 if (this->cache>=this->n) {
385 O2SCL_ERR(
"Cache mis-alignment in search_vec_ext::find_dec().",
392 #ifndef DOXYGEN_INTERNAL
403 #ifndef DOXYGEN_NO_O2NS