hash: add combiner adapter

This commit is contained in:
Danny Robson 2020-08-17 14:31:16 +10:00
parent fde275feb2
commit 3d5258b974
2 changed files with 49 additions and 0 deletions

View File

@ -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

48
hash/adapter.hpp Normal file
View File

@ -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 <danny@nerdcruft.net>
*/
#pragma once
#include "../bitwise.hpp"
#include <utility>
///////////////////////////////////////////////////////////////////////////////
namespace cruft::hash::adapter {
template <typename HashT>
class combine {
public:
using digest_t = typename HashT::digest_t;
using seed_t = typename HashT::seed_t;
template <typename ...ArgsT>
combine (ArgsT &&...args)
: m_inner (std::forward<ArgsT> (args)...)
{ ; }
decltype(auto)
operator() (cruft::view<u08 const*> data)
{
return m_inner (data);
}
template <typename ...TailT>
decltype(auto) operator() (
cruft::view<u08 const*> data,
TailT &&...tail
) {
return (*this) (data) ^ cruft::rotatel ((*this) (tail...), 6);
}
private:
HashT m_inner;
};
}