Maze Builder Docs 6.3.5
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
12
15struct uni_hash {
20 template <class T1>
21 std::size_t operator()(const T1& p) const {
22 auto hash1 = std::hash<T1>{}(p);
23 auto hash2 = std::hash<T1>{}(p) + 0x9e3779b9;
24 return hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + (hash1 >> 2));
25 }
26};
27
30struct pair_hash {
31
37 template <class T1, class T2>
38 std::size_t operator()(const std::pair<T1, T2>& p) const {
39 auto hash1 = std::hash<T1>{}(p.first);
40 auto hash2 = std::hash<T2>{}(p.second);
41 return hash1 ^ hash2;
42 }
43}; // pair_hash
44
47struct tri_hash {
54 template <class T1, class T2, class T3>
55 std::size_t operator()(const std::tuple<T1, T2, T3>& p) const {
56 auto hash1 = std::hash<T1>{}(std::get<0>(p));
57 auto hash2 = std::hash<T2>{}(std::get<1>(p));
58 auto hash3 = std::hash<T3>{}(std::get<2>(p));
59 return hash1 ^ hash2 ^ hash3;
60 }
61};
62
66
71 template <typename T>
72 std::size_t operator()(const std::weak_ptr<T>& weak) const {
73 if (auto shared = weak.lock()) {
74 return std::hash<std::shared_ptr<T>>{}(shared);
75 }
76
77 // Return 0 for expired weak_ptr
78 return 0;
79 }
80};
81
82} // namespace mazes
83
84#endif // HASH_FUNCS_H
Namespace for the maze builder.
Definition algo_interface.h:9
Hashing function to store a block's (x, z) position.
Definition hash_funcs.h:30
std::size_t operator()(const std::pair< T1, T2 > &p) const
Hash function for a pair.
Definition hash_funcs.h:38
Hashing function to store a block's (x, y, z) position.
Definition hash_funcs.h:47
std::size_t operator()(const std::tuple< T1, T2, T3 > &p) const
Hash function for a tuple.
Definition hash_funcs.h:55
A hash function object for a single value.
Definition hash_funcs.h:15
std::size_t operator()(const T1 &p) const
Hash function for a single.
Definition hash_funcs.h:21
Hashing function to store a weak_ptr.
Definition hash_funcs.h:65
std::size_t operator()(const std::weak_ptr< T > &weak) const
Hashing function.
Definition hash_funcs.h:72