Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_hash.hpp
Go to the documentation of this file.
1#pragma once
2#include "../foray_basics.hpp"
3
4namespace foray::util {
5 template <typename T>
6 inline void AccumulateHash(size_t& hash, const T& v)
7 {
8 // https://www.boost.org/doc/libs/1_55_0/doc/html/hash/reference.html#boost.hash_combine
9 // https://www.boost.org/LICENSE_1_0.txt
10 size_t vhash = std::hash<T>{}(v);
11 hash ^= vhash + 0x9e3779b9 + (hash << 6) + (hash >> 2);
12 }
13
15 inline void AccumulateRaw(size_t& hash, const void* data, size_t size)
16 {
17 uint64_t byteIndex = 0;
18 const uint64_t* data64 = reinterpret_cast<const uint64_t*>(data);
19 const uint8_t* data8 = reinterpret_cast<const uint8_t*>(data);
20
21 for(; byteIndex < size; byteIndex += 8)
22 {
23 AccumulateHash(hash, data64[byteIndex / 8]);
24 }
25 for(; byteIndex < size; byteIndex++)
26 {
27 AccumulateHash(hash, data8[byteIndex]);
28 }
29 }
30
31} // namespace foray
Definition foray_dualbuffer.hpp:5
void AccumulateRaw(size_t &hash, const void *data, size_t size)
Calculates a hash value for any block of memory.
Definition foray_hash.hpp:15
void AccumulateHash(size_t &hash, const T &v)
Definition foray_hash.hpp:6