From f1d902ce9b08e166b33fe5f902a33cd950810d2f Mon Sep 17 00:00:00 2001 From: Merry Date: Sun, 1 May 2022 18:26:39 +0100 Subject: [PATCH] mcl: hash: Add xmrx --- include/mcl/hash/xmrx.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 include/mcl/hash/xmrx.hpp diff --git a/include/mcl/hash/xmrx.hpp b/include/mcl/hash/xmrx.hpp new file mode 100644 index 0000000..ebc0fb6 --- /dev/null +++ b/include/mcl/hash/xmrx.hpp @@ -0,0 +1,30 @@ +// This file is part of the mcl project. +// Copyright (c) 2022 merryhime +// SPDX-License-Identifier: MIT + +// Reference: http://jonkagstrom.com/bit-mixer-construction/ + +#include + +#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 +struct avalanche_xmrx { + size_t operator()(const T& value) + { + return xmrx(std::hash{}(value)); + } +}; + +} // namespace mcl::hash