61 lines
1.9 KiB
C++
61 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include "tl/detail/prologue.h"
|
|
#include "EASTL/functional.h"
|
|
|
|
namespace tl
|
|
{
|
|
|
|
using namespace eastl;
|
|
|
|
template <class T>
|
|
constexpr inline void hash_and_combine(uint32_t& seed, const T& v) noexcept
|
|
{
|
|
//the result of the hasher is size_t so - if used in arithmetic - it might produce different results in 32 and 64 bit platforms
|
|
//therefore we cast it here to 32 bit.
|
|
tl::hash<T> hasher;
|
|
seed ^= static_cast<uint32_t>(hasher(v)) + static_cast<uint32_t>(0x9e3779b9) + (seed << 6) + (seed >> 2);
|
|
}
|
|
|
|
template <class T>
|
|
constexpr inline void hash_and_combine(uint64_t& seed, const T& v) noexcept
|
|
{
|
|
//the result of the hasher is size_t so - if used in arithmetic - it might produce different results in 32 and 64 bit platforms
|
|
//therefore we cast it here to 32 bit.
|
|
tl::hash<T> hasher;
|
|
seed ^= static_cast<uint32_t>(hasher(v)) + 0xA6E9377DAF75BDFEULL + (seed << 6) + (seed >> 2);
|
|
}
|
|
|
|
#if defined(TL_PLATFORM_OSX_FAMILY)
|
|
template <class T>
|
|
constexpr inline void hash_and_combine(size_t& seed, const T& v) noexcept
|
|
{
|
|
tl::hash<T> hasher;
|
|
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
|
}
|
|
#endif
|
|
|
|
|
|
constexpr inline void hash_combine(uint32_t& seed, const uint32_t v) noexcept
|
|
{
|
|
//the result of the hasher is size_t so - if used in arithmetic - it might produce different results in 32 and 64 bit platforms
|
|
//therefore we cast it here to 32 bit.
|
|
seed ^= v + static_cast<uint32_t>(0x9e3779b9u) + (seed << 6) + (seed >> 2);
|
|
}
|
|
|
|
constexpr inline void hash_combine(uint64_t& seed, const uint64_t v) noexcept
|
|
{
|
|
//the result of the hasher is size_t so - if used in arithmetic - it might produce different results in 32 and 64 bit platforms
|
|
//therefore we cast it here to 32 bit.
|
|
seed ^= static_cast<uint32_t>(v) + 0xA6E9377DAF75BDFEULL + (seed << 6) + (seed >> 2);
|
|
}
|
|
|
|
#if defined(TL_PLATFORM_OSX_FAMILY)
|
|
constexpr inline void hash_combine(size_t& seed, const size_t v) noexcept
|
|
{
|
|
seed ^= v + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
|
}
|
|
#endif
|
|
|
|
}
|