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
plain_rdd.h
1#ifndef CPARK_PLAIN_RDD_H
2#define CPARK_PLAIN_RDD_H
3
4#include "base_rdd.h"
5
6namespace cpark {
7
20template <std::ranges::view R>
21class PlainRdd : public BaseRdd<PlainRdd<R>> {
22public:
24 friend Base;
25
26public:
27public:
28 constexpr explicit PlainRdd(R view, ExecutionContext* context)
29 : BaseRdd<PlainRdd<R>>{context}, view_{std::move(view)} {
30 static_assert(concepts::Rdd<PlainRdd<R>>, "Instance of PlainRdd does not satisfy Rdd concept.");
31 splits_.reserve(Base::splits_num_);
32
33 // Creates the splits for this Rdd. Each split contains two iterators that points to the values
34 // that this split has.
35 for (size_t i : std::views::iota(size_t{0}, Base::splits_num_)) {
36 size_t total_size = std::ranges::size(view_);
37 size_t split_size = (total_size + Base::splits_num_ - 1) / Base::splits_num_;
38 auto b = std::ranges::begin(view_), e = std::ranges::begin(view_);
39 std::ranges::advance(b, std::min(total_size, i * split_size));
40 std::ranges::advance(e, std::min(total_size, (i + 1) * split_size));
41 splits_.emplace_back(std::ranges::subrange{b, e}, Base::context_);
42 }
43 }
44
45 // Explicitly define default copy constrictor and assignment operator,
46 // because some linters or compilers can not define implicit copy constructors for this class,
47 // though they are supposed to do so.
48 // TODO: find out why.
49 constexpr PlainRdd(const PlainRdd&) = default;
50 PlainRdd& operator=(const PlainRdd&) = default;
51
52private:
53 constexpr auto beginImpl() const { return std::ranges::begin(splits_); }
54
55 constexpr auto endImpl() const { return std::ranges::end(splits_); }
56
57private:
58 R view_;
59 // A vector holding the splits for this rdd.
60 std::vector<ViewSplit<std::ranges::subrange<std::ranges::iterator_t<R>>>> splits_{};
61};
62
// end of c_Plain
64
65} // namespace cpark
66
67#endif //CPARK_PLAIN_RDD_H
Definition base_rdd.h:522
Definition base_rdd.h:94
Definition cpark.h:148
Definition plain_rdd.h:21
Definition base_rdd.h:53