#pragma once #include "tl/detail/prologue.h" #include "EASTL/functional.h" namespace tl { using namespace eastl; template 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 hasher; seed ^= static_cast(hasher(v)) + static_cast(0x9e3779b9) + (seed << 6) + (seed >> 2); } template 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 hasher; seed ^= static_cast(hasher(v)) + 0xA6E9377DAF75BDFEULL + (seed << 6) + (seed >> 2); } #if defined(TL_PLATFORM_OSX_FAMILY) template constexpr inline void hash_and_combine(size_t& seed, const T& v) noexcept { tl::hash 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(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(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 }