Toast Engine
Loading...
Searching...
No Matches
hash.hpp
1
7
8#pragma once
9
10namespace toast {
11
12inline constexpr uint64_t k_golden_gamma = 0x9e3779b97f4a7c15ull;
13
14[[nodiscard]]
15constexpr auto splitmix64(uint64_t value) noexcept -> uint64_t {
16 value = (value ^ (value >> 30)) * 0xbf58476d1ce4e5b9ull;
17 value = (value ^ (value >> 27)) * 0x94d049bb133111ebull;
18 return value ^ (value >> 31);
19}
20
21constexpr void hashCombine(uint64_t& seed, uint64_t value) noexcept {
22 seed = splitmix64(value + k_golden_gamma + seed);
23}
24
25constexpr void hashFloats(uint64_t& seed, const float* data, size_t count) noexcept {
26 for (size_t i = 0; i < count; ++i) {
27 hashCombine(seed, std::bit_cast<uint32_t>(data[i]));
28 }
29}
30
31}