VOX
A little voxel engine
Loading...
Searching...
No Matches
hashes.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_map>
4#include <glm/vec3.hpp>
5#include <glm/vec2.hpp>
6
7namespace std
8{
9 template<>
10 struct hash<glm::ivec3>
11 {
12 std::size_t operator()(const glm::ivec3 & v) const
13 {
14 static const unsigned int m = 0x5bd1e995U;
15
16 unsigned int hash = 0;
17 unsigned int k = v.x;
18
19 //first vector element
20 k *= m;
21 k ^= k >> 24;
22 k *= m;
23 hash *= m;
24 hash ^= k;
25 //second vector element
26 k = v.y;
27 k *= m;
28 k ^= k >> 24;
29 k *= m;
30 hash *= m;
31 hash ^= k;
32 //third vector element
33 k = v.z;
34 k *= m;
35 k ^= k >> 24;
36 k *= m;
37 hash *= m;
38 hash ^= k;
39
40 hash ^= hash >> 13;
41 hash *= m;
42 hash ^= hash >> 15;
43 return hash;
44 }
45 };
46
47 template<>
48 struct hash<glm::ivec2>
49 {
50 std::size_t operator()(const glm::ivec2 & v) const
51 {
52 static const unsigned int m = 0x5bd1e995U;
53
54 unsigned int hash = 0;
55 unsigned int k = v.x;
56
57 //first vector element
58 k *= m;
59 k ^= k >> 24;
60 k *= m;
61 hash *= m;
62 hash ^= k;
63 //second vector element
64 k = v.y;
65 k *= m;
66 k ^= k >> 24;
67 k *= m;
68 hash *= m;
69 hash ^= k;
70
71 hash ^= hash >> 13;
72 hash *= m;
73 hash ^= hash >> 15;
74 return hash;
75 }
76 };
77}
Definition: ObjLoader.hpp:65
std::size_t operator()(const glm::ivec2 &v) const
Definition: hashes.hpp:50
std::size_t operator()(const glm::ivec3 &v) const
Definition: hashes.hpp:12