16 #ifndef GRPPI_COMMON_REDUCE_PATTERN_H
17 #define GRPPI_COMMON_REDUCE_PATTERN_H
28 template <
typename Combiner,
typename Identity>
40 window_size_{wsize}, offset_{
offset},
41 identity_{id}, combiner_{combine_op}
55 items.push_back(std::forward<Identity>(item));
64 return !items.empty() && (
static_cast<int>(items.size()) >= window_size_);
71 Combiner
combiner()
const {
return combiner_; }
83 int offset()
const {
return offset_; }
91 auto red = e.reduce(items.begin(), items.size(), identity_, combiner_);
92 if (offset_ > window_size_) {
93 remaining = offset_ - window_size_;
97 items.erase(items.begin(), std::next(items.begin(), offset_));
113 std::vector<Identity> items{};
122 template <
typename C,
typename I>
127 template <
typename T>
130 template <
typename T>
Representation of reduce pattern. Represents a reduction that can be used as a stage on a pipeline.
Definition: reduce_pattern.h:29
auto reduce_window(const E &e)
Reduce values from a window.
Definition: reduce_pattern.h:90
Combiner combiner() const
Get the combiner.
Definition: reduce_pattern.h:71
int window_size() const
Get the window size.
Definition: reduce_pattern.h:77
int offset() const
Get the offset.
Definition: reduce_pattern.h:83
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:50
bool reduction_needed() const
Check if a reduction can be performed.
Definition: reduce_pattern.h:63
reduce_t(int wsize, int offset, Identity id, Combiner &&combine_op)
Construct a reduction pattern object.
Definition: reduce_pattern.h:39
auto operator()(T &&)
Definition: reduce_pattern.h:103
Definition: callable_traits.h:21
std::enable_if_t< is_reduce< T >, int > requires_reduce
Definition: reduce_pattern.h:131
constexpr bool is_reduce
Definition: reduce_pattern.h:128
Definition: reduce_pattern.h:120