algorithm/hash.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_HASH_HPP
26 #define CRYPTO3_HASH_HPP
27 
30 
31 #include <nil/crypto3/detail/type_traits.hpp>
32 
33 namespace nil {
34  namespace crypto3 {
75  template<typename Hash, typename InputIterator, typename OutputIterator>
76  typename std::enable_if<!boost::accumulators::detail::is_accumulator_set<OutputIterator>::value,
77  OutputIterator>::type
78  hash(InputIterator first, InputIterator last, OutputIterator out) {
79  typedef accumulator_set<Hash> HashAccumulator;
80 
83 
84  return HashImpl(first, last, std::move(out), HashAccumulator());
85  }
86 
102  template<typename Hash, typename InputIterator, typename HashAccumulator = accumulator_set<Hash>>
103  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<HashAccumulator>::value,
104  HashAccumulator>::type &
105  hash(InputIterator first, InputIterator last, HashAccumulator &sh) {
106  typedef hashes::detail::ref_hash_impl<HashAccumulator> StreamHashImpl;
108 
109  return HashImpl(first, last, std::forward<HashAccumulator>(sh));
110  }
111 
126  template<typename Hash, typename InputIterator, typename HashAccumulator = accumulator_set<Hash>>
127  hashes::detail::range_hash_impl<hashes::detail::value_hash_impl<typename std::enable_if<
128  boost::accumulators::detail::is_accumulator_set<HashAccumulator>::value, HashAccumulator>::type>>
129  hash(InputIterator first, InputIterator last) {
132 
133  return HashImpl(first, last, HashAccumulator());
134  }
135 
150  template<typename Hash, typename SinglePassRange, typename OutputIterator>
151  typename std::enable_if<::nil::crypto3::detail::is_iterator<OutputIterator>::value, OutputIterator>::type
152  hash(const SinglePassRange &rng, OutputIterator out) {
153  typedef accumulator_set<Hash> HashAccumulator;
154 
157 
158  return HashImpl(rng, std::move(out), HashAccumulator());
159  }
160 
175  template<typename Hash, typename SinglePassRange, typename HashAccumulator = accumulator_set<Hash>>
176  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<HashAccumulator>::value,
177  HashAccumulator>::type &
178  hash(const SinglePassRange &rng, HashAccumulator &sh) {
179  typedef hashes::detail::ref_hash_impl<HashAccumulator> StreamHashImpl;
181 
182  return HashImpl(rng, std::forward<HashAccumulator>(sh));
183  }
184 
198  template<typename Hash, typename SinglePassRange, typename HashAccumulator = accumulator_set<Hash>>
199  hashes::detail::range_hash_impl<hashes::detail::value_hash_impl<HashAccumulator>>
200  hash(const SinglePassRange &r) {
201 
204 
205  return HashImpl(r, HashAccumulator());
206  }
207 
222  template<typename Hash, typename T, typename OutputIterator>
223  typename std::enable_if<::nil::crypto3::detail::is_iterator<OutputIterator>::value, OutputIterator>::type
224  hash(std::initializer_list<T> list, OutputIterator out) {
225  typedef accumulator_set<Hash> HashAccumulator;
226 
229 
230  return HashImpl(list, std::move(out), HashAccumulator());
231  }
232 
247  template<typename Hash, typename T, typename HashAccumulator = accumulator_set<Hash>>
248  typename std::enable_if<boost::accumulators::detail::is_accumulator_set<HashAccumulator>::value,
249  HashAccumulator>::type &
250  hash(std::initializer_list<T> rng, HashAccumulator &sh) {
251  typedef hashes::detail::ref_hash_impl<HashAccumulator> StreamHashImpl;
253 
254  return HashImpl(rng, std::forward<HashAccumulator>(sh));
255  }
256 
270  template<typename Hash, typename T, typename HashAccumulator = accumulator_set<Hash>>
271  hashes::detail::range_hash_impl<hashes::detail::value_hash_impl<HashAccumulator>>
272  hash(std::initializer_list<T> r) {
273 
276 
277  return HashImpl(r, HashAccumulator());
278  }
279  } // namespace crypto3
280 } // namespace nil
281 
282 #endif // CRYPTO3_HASH_HPP
std::enable_if<!boost::accumulators::detail::is_accumulator_set< OutputIterator >::value, OutputIterator >::type hash(InputIterator first, InputIterator last, OutputIterator out)
Definition: algorithm/hash.hpp:78
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
Definition: pair.hpp:31
Definition: hash_state.hpp:43
Definition: hash_value.hpp:172
Definition: hash_value.hpp:45