diff options
Diffstat (limited to 'include/o3tl/hash_combine.hxx')
-rw-r--r-- | include/o3tl/hash_combine.hxx | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/o3tl/hash_combine.hxx b/include/o3tl/hash_combine.hxx index 139ee981699c..f56beda62672 100644 --- a/include/o3tl/hash_combine.hxx +++ b/include/o3tl/hash_combine.hxx @@ -12,6 +12,17 @@ namespace o3tl { template <typename T, typename N> +inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& nSeed, T const* pValue, size_t nCount) +{ + static_assert(sizeof(nSeed) == 4); + for (size_t i = 0; i < nCount; ++i) + { + nSeed ^= std::hash<T>{}(*pValue) + 0x9E3779B9u + (nSeed << 6) + (nSeed >> 2); + ++pValue; + } +} + +template <typename T, typename N> inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& nSeed, T const& nValue) { static_assert(sizeof(nSeed) == 4); @@ -19,6 +30,17 @@ inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& nSeed, T const& nValue } template <typename T, typename N> +inline std::enable_if_t<(sizeof(N) == 8)> hash_combine(N& nSeed, T const* pValue, size_t nCount) +{ + static_assert(sizeof(nSeed) == 8); + for (size_t i = 0; i < nCount; ++i) + { + nSeed ^= std::hash<T>{}(*pValue) + 0x9E3779B97F4A7C15llu + (nSeed << 12) + (nSeed >> 4); + ++pValue; + } +} + +template <typename T, typename N> inline std::enable_if_t<(sizeof(N) == 8)> hash_combine(N& nSeed, T const& nValue) { static_assert(sizeof(nSeed) == 8); |