c++ - Effective search in specific intervals -
suppose have double value(x
) , need find in interval below belongs , return corresponding value:
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
Post a Comment