From 3d5258b974cd4d5a5833bb474a1e85f6e728d23b Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 17 Aug 2020 14:31:16 +1000 Subject: [PATCH] hash: add combiner adapter --- CMakeLists.txt | 1 + hash/adapter.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 hash/adapter.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 04fb862c..37a65ed1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -366,6 +366,7 @@ list ( geom/tri.hpp hash.hpp hash/fwd.hpp + hash/adapter.hpp hash/adler.cpp hash/adler.hpp hash/buzhash.hpp diff --git a/hash/adapter.hpp b/hash/adapter.hpp new file mode 100644 index 00000000..dde20a18 --- /dev/null +++ b/hash/adapter.hpp @@ -0,0 +1,48 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2020, Danny Robson + */ + +#pragma once + +#include "../bitwise.hpp" + +#include + + +/////////////////////////////////////////////////////////////////////////////// +namespace cruft::hash::adapter { + template + class combine { + public: + using digest_t = typename HashT::digest_t; + using seed_t = typename HashT::seed_t; + + template + combine (ArgsT &&...args) + : m_inner (std::forward (args)...) + { ; } + + + decltype(auto) + operator() (cruft::view data) + { + return m_inner (data); + } + + + template + decltype(auto) operator() ( + cruft::view data, + TailT &&...tail + ) { + return (*this) (data) ^ cruft::rotatel ((*this) (tail...), 6); + } + + private: + HashT m_inner; + }; +} \ No newline at end of file