mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 19:39:42 +00:00
Merge branch 'fix_hash_combine' into 'master'
Support seed type different from std::size_t for hashCombine See merge request OpenMW/openmw!1391
This commit is contained in:
commit
d0263b6dda
1 changed files with 9 additions and 4 deletions
|
@ -1,14 +1,19 @@
|
||||||
#ifndef MISC_HASH_H
|
#ifndef MISC_HASH_H
|
||||||
#define MISC_HASH_H
|
#define MISC_HASH_H
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace Misc
|
namespace Misc
|
||||||
{
|
{
|
||||||
/// Implemented similar to the boost::hash_combine
|
/// Implemented similar to the boost::hash_combine
|
||||||
template <class T>
|
template <class Seed, class T>
|
||||||
inline void hashCombine(std::size_t& seed, const T& v)
|
inline void hashCombine(Seed& seed, const T& v)
|
||||||
{
|
{
|
||||||
|
static_assert(sizeof(Seed) >= sizeof(std::size_t), "Resulting hash will be truncated");
|
||||||
std::hash<T> hasher;
|
std::hash<T> hasher;
|
||||||
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
|
seed ^= static_cast<Seed>(hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue