Grindstone Game Engine
v0.2.0
An open source game engine and toolkit.
Toggle main menu visibility
Loading...
Searching...
No Matches
Hash.hpp
1
#pragma once
2
3
#include "IntTypes.hpp"
4
5
namespace
Grindstone {
6
using
HashValue = Uint64;
7
8
namespace
Hash {
9
constexpr
HashValue MurmurOAAT64(
const
char
* key) {
10
HashValue h(525201411107845655ull);
11
for
(; *key; ++key) {
12
h ^= *key;
13
h *= 0x5bd1e9955bd1e995;
14
h ^= h >> 47;
15
}
16
return
h;
17
}
18
19
constexpr
HashValue MurmurOAAT64(
const
char
* key,
size_t
length) {
20
HashValue h(525201411107845655ull);
21
for
(
size_t
i = 0; i < length; ++i) {
22
h ^= key[i];
23
h *= 0x5bd1e9955bd1e995;
24
h ^= h >> 47;
25
}
26
return
h;
27
}
28
29
constexpr
HashValue MurmurOAAT64(HashValue h,
const
char
* key) {
30
for
(; *key; ++key) {
31
h ^= *key;
32
h *= 0x5bd1e9955bd1e995;
33
h ^= h >> 47;
34
}
35
return
h;
36
}
37
38
constexpr
HashValue CombineMurmurOAAT64(HashValue h,
const
char
* key,
size_t
length) {
39
for
(
size_t
i = 0; i < length; ++i) {
40
h ^= key[i];
41
h *= 0x5bd1e9955bd1e995;
42
h ^= h >> 47;
43
}
44
return
h;
45
}
46
47
// Similar to boost hash_combine library, to be used with std::hash. Taken from
48
// https://stackoverflow.com/questions/2590677/how-do-i-combine-hash-values-in-c0x
49
inline
void
Combine([[maybe_unused]] std::size_t& seed) {}
50
51
template
<
typename
T,
typename
... Rest>
52
inline
void
Combine(std::size_t& seed,
const
T& v, Rest... rest) {
53
std::hash<T> hasher;
54
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
55
Combine(seed, rest...);
56
}
57
58
struct
HashPair
{
59
template
<
class
T1,
class
T2>
60
size_t
operator()(
const
std::pair<T1, T2>& p)
const
{
61
size_t
hash1 = std::hash<T1>{}(p.first);
62
size_t
hash2 = std::hash<T2>{}(p.second);
63
64
return
hash1 ^ (hash2 + 0x9e3779b9 + (hash1 << 6) + (hash1 >> 2));
65
}
66
};
67
68
};
69
70
}
Grindstone::Hash::HashPair
Definition
Hash.hpp:58
sources
code
Common
Hash.hpp
Generated by
1.17.0