1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00
OpenMW/components/misc/hash.hpp
florent.teppe 21bd28542a Applies review advice
2d coord hash moved to hash.hpp file
format version adds suffix to be more coherent
don't use ESM::RefId::sEmpty
RefId equality with string_view, conversion to refId unecessary
action teleport remove test that mCellId is empty
removes some const references, when copy is enough
invalid refid => empty refid
removes useless change
2023-04-03 14:17:35 +02:00

28 lines
798 B
C++

#ifndef MISC_HASH_H
#define MISC_HASH_H
#include <cstddef>
#include <cstdint>
#include <functional>
namespace Misc
{
/// Implemented similar to the boost::hash_combine
template <class Seed, class T>
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;
seed ^= static_cast<Seed>(hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
// Comes from https://stackoverflow.com/questions/2634690/good-hash-function-for-a-2d-index
// Effective Java (2nd edition) is cited as the source
inline std::size_t hash2dCoord(int32_t x, int32_t y)
{
return (53 + std::hash<int32_t>{}(x)) * 53 + std::hash<int32_t>{}(y);
}
}
#endif