Maze Builder Docs 7.5.6
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
9namespace mazes
10{
11
13
16 struct uni_hash
17 {
22 template <class T1>
23 std::size_t operator()(const T1 &p) const
24 {
25 auto hash1 = std::hash<T1>{}(p);
26 auto hash2 = std::hash<T1>{}(p) + 0x9e3779b9;
27 return hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + (hash1 >> 2));
28 }
29 };
30
33 struct pair_hash
34 {
35
41 template <class T1, class T2>
42 std::size_t operator()(const std::pair<T1, T2> &p) const
43 {
44 auto hash1 = std::hash<T1>{}(p.first);
45 auto hash2 = std::hash<T2>{}(p.second);
46 return hash1 ^ hash2;
47 }
48 }; // pair_hash
49
52 struct tri_hash
53 {
60 template <class T1, class T2, class T3>
61 std::size_t operator()(const std::tuple<T1, T2, T3> &p) const
62 {
63 auto hash1 = std::hash<T1>{}(std::get<0>(p));
64 auto hash2 = std::hash<T2>{}(std::get<1>(p));
65 auto hash3 = std::hash<T3>{}(std::get<2>(p));
66 return hash1 ^ hash2 ^ hash3;
67 }
68 };
69
73 {
74
79 template <typename T>
80 std::size_t operator()(const std::weak_ptr<T> &weak) const
81 {
82 if (auto shared = weak.lock())
83 {
84 return std::hash<std::shared_ptr<T>>{}(shared);
85 }
86
87 // Return 0 for expired weak_ptr
88 return 0;
89 }
90 };
91
92} // namespace mazes
93
94#endif // HASH_FUNCS_H
Namespace for the maze builder.
Definition algo_interface.h:6
Hashing function to store a block's (x, z) position.
Definition hash_funcs.h:34
std::size_t operator()(const std::pair< T1, T2 > &p) const
Hash function for a pair.
Definition hash_funcs.h:42
Hashing function to store a block's (x, y, z) position.
Definition hash_funcs.h:53
std::size_t operator()(const std::tuple< T1, T2, T3 > &p) const
Hash function for a tuple.
Definition hash_funcs.h:61
A hash function object for a single value.
Definition hash_funcs.h:17
std::size_t operator()(const T1 &p) const
Hash function for a single.
Definition hash_funcs.h:23
Hashing function to store a weak_ptr.
Definition hash_funcs.h:73
std::size_t operator()(const std::weak_ptr< T > &weak) const
Hashing function.
Definition hash_funcs.h:80