c++ - Effective search in specific intervals -


suppose have double value(x) , need find in interval below belongs , return corresponding value:

enter image description here

i want know effective way this.
need call function dosen of times. may keep these values in set , binary search, or check if/else statements?

thanks in advance.

you can use std::map this:

std::map<double, double> valuemap; valuemap[1.0e-5] = 1.0; valuemap[1.0e-4] = 10.0; valuemap[1.0e-3] = 100.0; ... // value map, use lower_bound: double result = *valuemap.lower_bound(5.0e-4); //this return 1.0 double result2 = *valuemap.lower_bound(5.0e-3); //this return 10.0 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -