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
union_rdd.h
1#ifndef CPARK_UNION_RDD_H
2#define CPARK_UNION_RDD_H
3
4#include <vector>
5
6#include "base_rdd.h"
7#include "cassert"
8#include "merged_view.h"
9#include "utils.h"
10
11namespace cpark {
12
29template <concepts::Rdd R1, concepts::Rdd R2>
30requires std::is_same_v<utils::RddElementType<R1>, utils::RddElementType<R2>> class UnionRdd
31 : public BaseRdd<UnionRdd<R1, R2>> {
32public:
34 friend Base;
35
41 constexpr UnionRdd(const R1& prev1, const R2& prev2) : Base{prev1, false} {
42 static_assert(concepts::Rdd<UnionRdd<R1, R2>>,
43 "Instance of UnionRdd does not satisfy Rdd concept.");
44 auto empty_split_1 = std::ranges::subrange{prev1.front().end(), prev1.front().end()};
45 auto empty_split_2 = std::ranges::subrange{prev2.front().end(), prev2.front().end()};
46
47 // Push the splits from RDD1.
48 for (const concepts::Split auto& prev_split : prev1) {
49 splits_.emplace_back(MergedTwoDiffView(std::ranges::subrange(prev_split), empty_split_2),
51 splits_.back().addDependency(prev_split);
52 }
53 // Push the splits from RDD2.
54 for (const concepts::Split auto& prev_split : prev2) {
55 splits_.emplace_back(MergedTwoDiffView(empty_split_1, std::ranges::subrange(prev_split)),
57 splits_.back().addDependency(prev_split);
58 }
59 }
60
61 constexpr UnionRdd(const UnionRdd&) = default;
62 UnionRdd& operator=(const UnionRdd&) = default;
63
64private:
65 constexpr auto beginImpl() const { return std::ranges::begin(splits_); }
66 constexpr auto endImpl() const { return std::ranges::end(splits_); }
67
68private:
69 using SplitType1 = std::ranges::range_value_t<R1>;
70 using SplitType2 = std::ranges::range_value_t<R2>;
71 using SubrangeSplitType1 = std::ranges::subrange<std::ranges::iterator_t<SplitType1>>;
72 using SubrangeSplitType2 = std::ranges::subrange<std::ranges::iterator_t<SplitType2>>;
73 using UnionViewType = MergedTwoDiffView<SubrangeSplitType1, SubrangeSplitType2>;
74 std::vector<ViewSplit<UnionViewType>> splits_;
75};
76
// end of t_Union
78
79} // namespace cpark
80
81#endif //CPARK_UNION_RDD_H
Definition base_rdd.h:522
Definition base_rdd.h:94
auto end() const
Definition base_rdd.h:151
Definition merged_view.h:139
Definition union_rdd.h:31
constexpr UnionRdd(const R1 &prev1, const R2 &prev2)
Definition union_rdd.h:41
Definition base_rdd.h:53
Definition base_rdd.h:44