Wildmeshing Toolkit
Loading...
Searching...
No Matches
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
11namespace wmtk {
12template <typename T>
13class hash
14{
15};
16template <>
18{
19public:
20 size_t operator()(const wmtk::attribute::AttributeHandle& handle) const noexcept;
21};
22template <typename T>
24{
25public:
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};
43template <>
45{
46public:
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
52template <>
53class std::hash<wmtk::attribute::AttributeHandle>
54 : public wmtk::hash<wmtk::attribute::AttributeHandle>
55{
56};
57template <>
58class std::hash<wmtk::attribute::TypedAttributeHandle<double>>
59 : public wmtk::hash<wmtk::attribute::TypedAttributeHandle<double>>
60{
61};
62template <>
63class std::hash<wmtk::attribute::TypedAttributeHandle<int64_t>>
64 : public wmtk::hash<wmtk::attribute::TypedAttributeHandle<int64_t>>
65{
66};
67template <>
68class std::hash<wmtk::attribute::TypedAttributeHandle<char>>
69 : public wmtk::hash<wmtk::attribute::TypedAttributeHandle<char>>
70{
71};
72template <>
73class std::hash<wmtk::attribute::TypedAttributeHandle<wmtk::Rational>>
74 : public wmtk::hash<wmtk::attribute::TypedAttributeHandle<wmtk::Rational>>
75{
76};
77template <>
78class 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)
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.