CPARK 1.0
A light-weighted, distributed computing framework for C++ that offers a fast and general-purpose large data processing solution.
Loading...
Searching...
No Matches
count.h
1#ifndef CPARK_COUNT_H
2#define CPARK_COUNT_H
3
4#include <future>
5#include <vector>
6#include <numeric>
7
8#include "base_rdd.h"
9#include "utils.h"
10
11namespace cpark {
12
23class Count {
24public:
26 explicit Count() = default;
27
29 template <concepts::Rdd R>
30 unsigned long long operator()(const R& rdd) const {
31 // Parallel compute the result.
32 std::vector<std::future<unsigned long long>> futures{};
33 for (const concepts::Split auto& split : rdd)
34 futures.emplace_back(std::async([this, &split]() {
35 return static_cast<unsigned long long>(split.size());
36 }));
37
38 auto results =
39 std::ranges::subrange(futures) |
40 std::views::transform([](std::future<unsigned long long>& fut) { return fut.get(); });
41
42 return std::accumulate(results.begin(), results.end(), 0);
43 }
44};
45
49template <concepts::Rdd R>
50auto operator|(const R& r, const Count& count) {
51 return count(r);
52}
53
// end of a_Count
55
56} // namespace cpark
57
58#endif //CPARK_COUNT_H
Definition base_rdd.h:94
auto end() const
Definition base_rdd.h:151
auto begin() const
Definition base_rdd.h:142
Definition count.h:23
Count()=default
unsigned long long operator()(const R &rdd) const
Definition count.h:30
Definition base_rdd.h:44
auto operator|(const R &r, const Collect &collect)
Definition collect.h:48