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
collect.h
1#ifndef CPARK_COLLECT_H
2#define CPARK_COLLECT_H
3
4#include <future>
5#include <vector>
6
7#include "base_rdd.h"
8#include "utils.h"
9
10namespace cpark {
11
22class Collect {
23public:
25 explicit Collect() = default;
27 template <concepts::Rdd R, typename T = utils::RddElementType<R>>
28 std::vector<T> operator()(const R& rdd) const {
29 std::vector<std::future<std::vector<T>>> futures{};
30 for (const auto& split : rdd) {
31 futures.emplace_back(std::async([this, &split]() {
32 return std::vector<T>(std::ranges::begin(split), std::ranges::end(split));
33 }));
34 }
35 std::vector<T> result{};
36 for (auto& fut : futures) {
37 auto split_result = fut.get();
39 }
40 return result;
41 }
42};
43
47template <concepts::Rdd R>
48auto operator|(const R& r, const Collect& collect) {
49 return collect(r);
50}
51
// end of a_Collect
59
60} // namespace cpark
61
62#endif // CPARK_COLLECT_H
Definition base_rdd.h:94
auto end() const
Definition base_rdd.h:151
auto begin() const
Definition base_rdd.h:142
Definition collect.h:22
std::vector< T > operator()(const R &rdd) const
Definition collect.h:28
Collect()=default
auto operator|(const R &r, const Collect &collect)
Definition collect.h:48