21 #ifndef GRPPI_COMMON_REDUCE_PATTERN_H 22 #define GRPPI_COMMON_REDUCE_PATTERN_H 33 template <
typename Combiner,
typename Identity>
45 window_size_{wsize}, offset_{
offset},
46 identity_{
id}, combiner_{combine_op}
60 items.push_back(std::forward<Identity>(item));
68 return !items.empty() && (items.size() >= window_size_);
75 Combiner
combiner()
const {
return combiner_; }
87 int offset()
const {
return offset_; }
95 auto red = e.reduce(items.begin(), items.size(), identity_, combiner_);
96 if (offset_ > window_size_) {
97 remaining = offset_ - window_size_;
101 items.erase(items.begin(), std::next(items.begin(), offset_));
117 std::vector<Identity> items{};
126 template <
typename C,
typename I>
131 template <
typename T>
134 template <
typename T>
Definition: callable_traits.h:26
reduce_t(int wsize, int offset, Identity id, Combiner &&combine_op)
Construct a reduction pattern object.
Definition: reduce_pattern.h:44
std::enable_if_t< is_reduce< T >, int > requires_reduce
Definition: reduce_pattern.h:135
constexpr bool is_reduce
Definition: reduce_pattern.h:132
Combiner combiner() const
Get the combiner.
Definition: reduce_pattern.h:75
Definition: reduce_pattern.h:124
auto reduce_window(const E &e)
Reduce values from a window.
Definition: reduce_pattern.h:94
int window_size() const
Get the window size.
Definition: reduce_pattern.h:81
Representation of reduce pattern. Represents a reduction that can be used as a stage on a pipeline...
Definition: reduce_pattern.h:34
int offset() const
Get the offset.
Definition: reduce_pattern.h:87
bool reduction_needed() const
Check if a reduction can be performed.
Definition: reduce_pattern.h:67
void add_item(Identity &&item)
Add an item to the reduction buffer. If there are remaining items before reaching the next window sta...
Definition: reduce_pattern.h:55
auto operator()(T &&item)
Definition: reduce_pattern.h:107