-
|
I want to make a hash map of type struct Point_hash {
std::size_t operator()(const K::Point_3& p) const noexcept {
p.exact(); // <---- Refine coordinates before calling CGAL::to_double
std::size_t seed{};
boost::hash_combine(seed, std::hash<double>()(CGAL::to_double(p.x())));
boost::hash_combine(seed, std::hash<double>()(CGAL::to_double(p.y())));
boost::hash_combine(seed, std::hash<double>()(CGAL::to_double(p.z())));
return seed;
}
};Does |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Yes, that's a way to ensure consistency. You can have a look at a closely related discussion there: #6000. Note that these calls to |
Beta Was this translation helpful? Give feedback.
-
|
I have come up with an optimization: struct Point_hash {
std::size_t operator()(const Point& p) const noexcept {
if (!p.x().approx().is_point() || !p.y().approx().is_point() || !p.z().approx().is_point()) {
p.exact();
}
std::size_t seed{};
boost::hash_combine(seed, std::hash<double>()(CGAL::to_double(p.x())));
boost::hash_combine(seed, std::hash<double>()(CGAL::to_double(p.y())));
boost::hash_combine(seed, std::hash<double>()(CGAL::to_double(p.z())));
return seed;
}
};(This makes the execution faster because most of the points are directly constructed from Is this safe? |
Beta Was this translation helpful? Give feedback.
Yes, that's a way to ensure consistency. You can have a look at a closely related discussion there: #6000.
Note that these calls to
exact()will nullify the "lazy exactness" mechanisms (meaning, delaying exact computations until it is really needed) ofEPECK, and it might be slower to use an unordered container within your program in the end.