mirror of
https://github.com/azahar-emu/mcl
synced 2025-11-06 23:20:08 +01:00
33 lines
620 B
C++
33 lines
620 B
C++
// This file is part of the mcl project.
|
|
// Copyright (c) 2022 merryhime
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// Reference: http://jonkagstrom.com/bit-mixer-construction/
|
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
|
|
#include "mcl/bit/rotate.hpp"
|
|
#include "mcl/stdint.hpp"
|
|
|
|
namespace mcl::hash {
|
|
|
|
constexpr size_t xmrx(size_t x)
|
|
{
|
|
x ^= x >> 32;
|
|
x *= 0xff51afd7ed558ccd;
|
|
x ^= bit::rotate_right(x, 47) ^ bit::rotate_right(x, 23);
|
|
return x;
|
|
}
|
|
|
|
template<typename T>
|
|
struct avalanche_xmrx {
|
|
size_t operator()(const T& value) const
|
|
{
|
|
return xmrx(std::hash<T>{}(value));
|
|
}
|
|
};
|
|
|
|
} // namespace mcl::hash
|