From cb06fb9b296f7cfafc76741013f3f9757a15fd6c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 24 Jul 2023 12:55:48 +1000 Subject: [PATCH] hash/mix: add a simple std compatible wrapper for hash::mix --- CMakeLists.txt | 2 ++ hash/mix.cpp | 1 + hash/mix.hpp | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 hash/mix.cpp create mode 100644 hash/mix.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 32532a20..3619bcb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -412,6 +412,8 @@ list ( hash/fnv1a.hpp hash/halfsipmix.cpp hash/halfsipmix.hpp + hash/mix.cpp + hash/mix.hpp hash/murmur/common.cpp hash/murmur/common.hpp hash/murmur.hpp diff --git a/hash/mix.cpp b/hash/mix.cpp new file mode 100644 index 00000000..0abe4721 --- /dev/null +++ b/hash/mix.cpp @@ -0,0 +1 @@ +#include "./mix.hpp" \ No newline at end of file diff --git a/hash/mix.hpp b/hash/mix.hpp new file mode 100644 index 00000000..dc9942a4 --- /dev/null +++ b/hash/mix.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "../hash.hpp" + +#include + + +namespace cruft::hash { + /// A std compatible adapter for a variadic 'mix' hash. + /// + /// It combines multiple values in a way that is unlikely to result in collisions. + /// + /// The exact implementation is not defined. + struct mixer { + template + auto operator () (ValueT &&...elements) + { + return cruft::hash::mix ( + std::forward (elements)... + ); + } + }; +} \ No newline at end of file