1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00
rpcs3/Utilities/hash.h
Lassi Hämäläinen e9e87b8bd9 Add missing #includes to header files
- Multiple header files where missing #includes to other headers that
  where used in the header. Correct header was included in correct
  order in source files which caused everything to compile.
- Added missing #includes so header files correctly include all their
  dependencies and fixes problems with IDEs being unable to parse
  headers correctly due to missing symbols
2019-06-25 17:11:10 +03:00

52 lines
984 B
C++

#pragma once
#include "Utilities/types.h"
namespace rpcs3
{
template<typename T>
static size_t hash_base(T value)
{
return static_cast<size_t>(value);
}
template<typename T, typename U>
static size_t hash_struct_base(const T& value)
{
// FNV 64-bit
size_t result = 14695981039346656037ull;
const U *bits = reinterpret_cast<const U*>(&value);
for (size_t n = 0; n < (sizeof(T) / sizeof(U)); ++n)
{
result ^= bits[n];
result *= 1099511628211ull;
}
return result;
}
template<typename T>
static size_t hash_struct(const T& value)
{
static constexpr auto block_sz = sizeof(T);
if constexpr ((block_sz & 0x7) == 0)
{
return hash_struct_base<T, u64>(value);
}
if constexpr ((block_sz & 0x3) == 0)
{
return hash_struct_base<T, u32>(value);
}
if constexpr ((block_sz & 0x1) == 0)
{
return hash_struct_base<T, u16>(value);
}
return hash_struct_base<T, u8>(value);
}
}