From dd3583909fff6aa00315df629e0abd6904ecce63 Mon Sep 17 00:00:00 2001 From: Nikita Ushakov Date: Wed, 25 Dec 2024 19:12:15 +0000 Subject: [PATCH] Make cb map as hash table --- src/hash.hpp | 20 ++++++++++++++++++++ src/plugin.hpp | 1 + 2 files changed, 21 insertions(+) create mode 100644 src/hash.hpp diff --git a/src/hash.hpp b/src/hash.hpp new file mode 100644 index 0000000..7db7194 --- /dev/null +++ b/src/hash.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace { + template + void hash_combine(std::size_t& seed, const T& v, const Rest&... rest) { + seed ^= std::hash{}(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + (hash_combine(seed, rest), ...); + } +} + +template +struct std::hash> { + std::size_t operator()(std::pair const& p) const noexcept { + std::size_t seed{}; + hash_combine(seed, p.first, p.second); + return seed; + } +}; diff --git a/src/plugin.hpp b/src/plugin.hpp index bb01438..53d2abe 100644 --- a/src/plugin.hpp +++ b/src/plugin.hpp @@ -1,6 +1,7 @@ #pragma once #include "callback.hpp" +#include "hash.hpp" #include #include