CPP-TOOLBOX
Loading...
Searching...
No Matches
hashing.hpp
Go to the documentation of this file.
1#ifndef HASHING_HPP
2#define HASHING_HPP
3
4#include <glm/glm.hpp>
5#include <functional>
6
7// Hash specialization for glm::vec3
8namespace std {
9template <> struct hash<glm::vec3> {
10 size_t operator()(const glm::vec3 &v) const {
11 size_t h1 = std::hash<float>{}(v.x);
12 size_t h2 = std::hash<float>{}(v.y);
13 size_t h3 = std::hash<float>{}(v.z);
14 return h1 ^ (h2 << 1) ^ (h3 << 2);
15 }
16};
17
18// Hash specialization for glm::vec2
19template <> struct hash<glm::vec2> {
20 size_t operator()(const glm::vec2 &v) const {
21 size_t h1 = std::hash<float>{}(v.x);
22 size_t h2 = std::hash<float>{}(v.y);
23 return h1 ^ (h2 << 1);
24 }
25};
26
27// Hash specialization for std::vector<T>
28template <typename T> struct hash<std::vector<T>> {
29 size_t operator()(const std::vector<T> &vec) const {
30 size_t result = 0;
31 for (const auto &elem : vec) {
32 result ^= std::hash<T>{}(elem) + 0x9e3779b9 + (result << 6) + (result >> 2); // Custom hash combination
33 }
34 return result;
35 }
36};
37
38} // namespace std
39
40#endif // HASHING_HPP
@ v
Definition input_state.hpp:48
Definition glm_printing.hpp:28
Definition hashing.hpp:8
size_t operator()(const glm::vec2 &v) const
Definition hashing.hpp:20
size_t operator()(const glm::vec3 &v) const
Definition hashing.hpp:10
size_t operator()(const std::vector< T > &vec) const
Definition hashing.hpp:29