Wildmeshing Toolkit
hash.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <functional>
5 
6 
7 // in general we're making classes implement the hashable interface - but these
8 // handles are litered around as simple objects so we're not enforcing that.
9 // Instead we're using std::hash as a visitor
10 
11 namespace wmtk {
12 template <typename T>
13 class hash
14 {
15 };
16 template <>
18 {
19 public:
20  size_t operator()(const wmtk::attribute::AttributeHandle& handle) const noexcept;
21 };
22 template <typename T>
24 {
25 public:
26  size_t operator()(const wmtk::attribute::TypedAttributeHandle<T>& handle) const noexcept
27  {
28  std::vector<size_t> data;
29  data.emplace_back(handle_hash(handle));
30  data.emplace_back(primitive_hash(handle));
31  const size_t r = wmtk::utils::vector_hash(data);
32  return r;
33  }
34  size_t handle_hash(const wmtk::attribute::TypedAttributeHandle<T>& handle) const noexcept
35  {
36  return hash<wmtk::attribute::AttributeHandle>{}(handle.m_base_handle);
37  }
38  size_t primitive_hash(const wmtk::attribute::TypedAttributeHandle<T>& handle) const noexcept
39  {
40  return wmtk::get_primitive_type_id(handle.primitive_type());
41  }
42 };
43 template <>
45 {
46 public:
47  inline size_t operator()(const wmtk::attribute::MeshAttributeHandle& handle) const noexcept;
48  inline size_t handle_hash(const wmtk::attribute::MeshAttributeHandle& handle) const noexcept;
49  inline size_t mesh_hash(const wmtk::attribute::MeshAttributeHandle& handle) const noexcept;
50 };
51 } // namespace wmtk
52 template <>
54  : public wmtk::hash<wmtk::attribute::AttributeHandle>
55 {
56 };
57 template <>
58 class std::hash<wmtk::attribute::TypedAttributeHandle<double>>
59  : public wmtk::hash<wmtk::attribute::TypedAttributeHandle<double>>
60 {
61 };
62 template <>
63 class std::hash<wmtk::attribute::TypedAttributeHandle<int64_t>>
64  : public wmtk::hash<wmtk::attribute::TypedAttributeHandle<int64_t>>
65 {
66 };
67 template <>
68 class std::hash<wmtk::attribute::TypedAttributeHandle<char>>
69  : public wmtk::hash<wmtk::attribute::TypedAttributeHandle<char>>
70 {
71 };
72 template <>
73 class std::hash<wmtk::attribute::TypedAttributeHandle<wmtk::Rational>>
74  : public wmtk::hash<wmtk::attribute::TypedAttributeHandle<wmtk::Rational>>
75 {
76 };
77 template <>
78 class std::hash<wmtk::attribute::MeshAttributeHandle>
79  : public wmtk::hash<wmtk::attribute::MeshAttributeHandle>
80 {
81 };
Internal handle representation used by MeshAttributes.
Handle that represents attributes for some mesh.
size_t primitive_hash(const wmtk::attribute::TypedAttributeHandle< T > &handle) const noexcept
Definition: hash.hpp:38
size_t handle_hash(const wmtk::attribute::TypedAttributeHandle< T > &handle) const noexcept
Definition: hash.hpp:34
size_t operator()(const wmtk::attribute::TypedAttributeHandle< T > &handle) const noexcept
Definition: hash.hpp:26
std::size_t vector_hash(const std::vector< size_t > &data)
Definition: vector_hash.cpp:28
Definition: Accessor.hpp:6
attribute::TypedAttributeHandle< T > TypedAttributeHandle
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.
attribute::AttributeHandle AttributeHandle