Maze Builder Docs 8.2.1
Loading...
Searching...
No Matches
hash_funcs.h
Go to the documentation of this file.
1#ifndef HASH_FUNCS_H
2#define HASH_FUNCS_H
3
4#include <functional>
5#include <memory>
6#include <tuple>
7#include <utility>
8
11namespace mazes
12{
15 struct uni_hash
16 {
21 template <class T1>
22 std::size_t operator()(const T1& p) const
23 {
24 auto hash1 = std::hash<T1>{}(p);
25 auto hash2 = std::hash<T1>{}(p) + 0x9e3779b9;
26 return hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + (hash1 >> 2));
27 }
28 };
29
32 struct pair_hash
33 {
39 template <class T1, class T2>
40 std::size_t operator()(const std::pair<T1, T2>& p) const
41 {
42 auto hash1 = std::hash<T1>{}(p.first);
43 auto hash2 = std::hash<T2>{}(p.second);
44 return hash1 ^ hash2;
45 }
46 }; // pair_hash
47
50 struct tri_hash
51 {
58 template <class T1, class T2, class T3>
59 std::size_t operator()(const std::tuple<T1, T2, T3>& p) const
60 {
61 auto hash1 = std::hash<T1>{}(std::get<0>(p));
62 auto hash2 = std::hash<T2>{}(std::get<1>(p));
63 auto hash3 = std::hash<T3>{}(std::get<2>(p));
64 return hash1 ^ hash2 ^ hash3;
65 }
66 };
67
71 {
76 template <typename T>
77 std::size_t operator()(const std::weak_ptr<T>& weak) const
78 {
79 if (auto shared = weak.lock())
80 {
81 return std::hash<std::shared_ptr<T>>{}(shared);
82 }
83
84 // Return 0 for expired weak_ptr
85 return 0;
86 }
87 };
88} // namespace mazes
89
90#endif // HASH_FUNCS_H
Hashing function to store a block's (x, z) position.
Definition hash_funcs.h:33
std::size_t operator()(const std::pair< T1, T2 > &p) const
Hash function for a pair.
Definition hash_funcs.h:40
Hashing function to store a block's (x, y, z) position.
Definition hash_funcs.h:51
std::size_t operator()(const std::tuple< T1, T2, T3 > &p) const
Hash function for a tuple.
Definition hash_funcs.h:59
A hash function object for a single value.
Definition hash_funcs.h:16
std::size_t operator()(const T1 &p) const
Hash function for a single value.
Definition hash_funcs.h:22
Hashing function to store a weak_ptr.
Definition hash_funcs.h:71
std::size_t operator()(const std::weak_ptr< T > &weak) const
Hashing function.
Definition hash_funcs.h:77