hi
This is related to this question
I have a vector of points that will, for instance, store 100K+ points.
std::vector<Point> point_vec;
I want to check if a position (x, y, z) to be added is already in point_vec
(represented by an instance of class Point
). The following function will check this (in a for
loop)
bool samePoints(const Point& p1,
const double x1,
const double y1,
const double z1) {
return fabs(p1.x - x1) < EPSILON &&
fabs(p1.y - y1) < EPSILON &&
fabs(p1.z - z1) < EPSILON;
}
But, I guess checking if x in list/ vector
will be a costly operation. I want to know if there is a better way to check if a) Points are equal (perhaps an operator "=" on class Point?? and (b) Is there some other , better data structure than `vector' that I should make use of. OR if there is an operation on vector that will speed up checking for 'same points'
For (b) please note that I need to std::sort these points as well. So any other data structure that you may suggest should be able to sort these points.
UPDATE
I want the points in the sorted state only. It is just that vector doesn't sort those (so I need to perform a sort operation. Should I use std::set<Point> point_set
instead of instead of std::vector <Point> point_vec
? IF SO: Is adding each point to a set a costly operation ? Or 'vector' sorting that I do in the end turns out costlier overall?