This is an simple use case of cpark basic operations.
#include <iostream>
#include <ranges>
#include <variant>
#include "generator_rdd.h"
#include "plain_rdd.h"
#include "reduce.h"
#include "transformed_rdd.h"
#include "zipped_rdd.h"
int main() {
using namespace cpark;
std::cout <<
"The debug name of customized config is " << customized_config.
getDebugName()
<< std::endl;
auto transformed_iota_view =
std::views::iota(1, 100 + 1) | std::views::transform([](auto x) { return x * x; });
concepts::Rdd
auto plain_rdd =
PlainRdd(transformed_iota_view, &default_context);
std::cout << "The plain Rdd has " << plain_rdd.size() << " splits." << std::endl;
concepts::Split auto first_plain_split = plain_rdd.front();
concepts::Split auto second_plain_split = plain_rdd[2];
concepts::Split auto last_plain_split = plain_rdd.back();
auto iterator_to_first_plain_split = plain_rdd.begin();
auto iterator_past_last_plain_split = plain_rdd.end();
auto iterator_to_first_element = first_plain_split.begin();
int first_element = first_plain_split.front();
std::cout << "The first split of plain rdd contains the following elements: ";
for (int x : first_plain_split) {
std::cout << x << ", ";
}
std::cout << std::endl;
std::cout << "The last split of plain rdd contains the following elements: ";
for (int x : plain_rdd.back()) {
std::cout << x << ", ";
}
std::cout << std::endl;
std::cout << "The first split of the generator rdd contains the following elements: ";
0, 50, [](auto x) { return std::to_string(x) + " hello"; }, &default_context);
for (const std::string& x : generator_rdd.front()) {
std::cout << x << ", ";
}
std::cout << std::endl;
auto transformed_rdd =
TransformedRdd(generator_rdd, [](
const auto& x) {
return x +
" world"; });
std::cout << "The elements in the fourth split of transformed rdd are: ";
for (const auto& x : transformed_rdd[3]) {
std::cout << x << ", ";
}
std::cout << std::endl;
auto transformed_rdd_2 = generator_rdd |
Transform([](
const auto& x) {
return x +
" my world"; });
std::cout << "The elements in the third split of another transformed rdd are: ";
for (const auto& x : transformed_rdd_2[2]) {
std::cout << x << ", ";
}
std::cout << std::endl;
int res = plain_rdd |
Reduce([](
int x,
int y) {
return x + y; });
std::cout << "The sum of the plain rdd is " << res << std::endl;
auto zipped_rdd =
ZippedRdd(generator_rdd, transformed_rdd);
std::cout << "The elements in the first split of zipped rdd are: ";
for (const auto& x : zipped_rdd[0]) {
std::cout << "(" << x.first << ", " << x.second << ")"
<< ", ";
}
std::cout << std::endl;
}
Config & setParallelTaskNum(size_t num=0) noexcept
Definition cpark.h:82
constexpr const std::string & getDebugName() const noexcept
Definition cpark.h:49
Config & setDebugName(std::string name) noexcept
Definition cpark.h:76
Config & setLogger(std::ostream *logger) noexcept
Definition cpark.h:101
Definition generator_rdd.h:27
Definition plain_rdd.h:21
Definition zipped_rdd.h:27