Skip to content

Instantly share code, notes, and snippets.

@giraldeau
Created February 8, 2021 14:00
Show Gist options
  • Save giraldeau/ba7422f4b5ac539559b6c17e759889f5 to your computer and use it in GitHub Desktop.
Save giraldeau/ba7422f4b5ac539559b6c17e759889f5 to your computer and use it in GitHub Desktop.
hash function for point with variable dim
template<int spacedim>
struct PointHashFunc
{
std::size_t
operator()(const dealii::Point<spacedim>&p) const
{
std::size_t h;
h = std::hash<double>()(p[0]);
if (spacedim > 1)
{
std::size_t h2 = std::hash<double>()(p[1]);
h = h ^ (h2 << 1);
}
if (spacedim > 2)
{
size_t h3 = std::hash<double>()(p[2]);
h = h ^ h3;
}
if (spacedim > 3)
{
AssertThrow(false, ExcNotImplemented());
}
return h;
}
}; // struct PointHashFunc
template<int spacedim, typename T>
using PointMap =
std::unordered_map<dealii::Point<spacedim>, T, PointHashFunc<spacedim> >;
@giraldeau
Copy link
Author

Credits to Jean-Paul Pelteret

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment