27 lines
569 B
C++
27 lines
569 B
C++
#pragma once
|
|
#include <string_view>
|
|
namespace meta
|
|
{
|
|
template <class T>
|
|
constexpr inline void hash_combine(size_t& seed, const T& v) noexcept
|
|
{
|
|
std::hash<T> hasher;
|
|
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
|
}
|
|
constexpr inline size_t string_hash(std::string_view str) noexcept
|
|
{
|
|
constexpr size_t fnv_offset_basis = 0xcbf29ce484222325;
|
|
constexpr size_t fnv_prime = 0x100000001b3;
|
|
|
|
auto hash = fnv_offset_basis;
|
|
for (auto& elem : str)
|
|
{
|
|
hash *= fnv_prime;
|
|
hash ^= elem;
|
|
}
|
|
hash *= fnv_prime;
|
|
hash ^= 0;
|
|
|
|
return hash;
|
|
}
|
|
} |