mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-08-29 14:50:52 +00:00
add numeric algorithm reduce, exclusive_scan, inclusize_scan
This commit is contained in:
parent
715cb40734
commit
2052058357
34 changed files with 1195 additions and 18 deletions
42
sprout/numeric/reduce.hpp
Normal file
42
sprout/numeric/reduce.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2017 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_NUMERIC_REDUCE_HPP
|
||||
#define SPROUT_NUMERIC_REDUCE_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/numeric/accumulate.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// reduce
|
||||
//
|
||||
// recursion depth:
|
||||
// O(log N)
|
||||
//
|
||||
template<typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::value_type
|
||||
reduce(InputIterator first, InputIterator last) {
|
||||
return sprout::accumulate(first, last, typename std::iterator_traits<InputIterator>::value_type());
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
reduce(InputIterator first, InputIterator last, T init) {
|
||||
return sprout::accumulate(first, last, init);
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename T, typename BinaryOperation>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) {
|
||||
return sprout::accumulate(first, last, init, binary_op);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_REDUCE_HPP
|
Loading…
Add table
Add a link
Reference in a new issue