Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++ aggregator for sort #349

Draft
wants to merge 6 commits into
base: future
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions runtime/agg/cpp/aggregators/sort/agg-bsd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef AGG_SORT_H
#define AGG_SORT_H

#include "main.h"
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstring>

inline constexpr cmd_opts g_options{
// TODO
};

bool compare(const std::string& str1, const std::string& str2)
{
return str1 < str2;
}

void aggregate() noexcept
{
std::string input1_top, input2_top;
bool refill1 = true, refill2 = true;
while (true)
{
if (refill1)
{
std::getline(input1(), input1_top);
if (!input1())
break;
refill1 = false;
}
if (refill2)
{
std::getline(input2(), input2_top);
if (!input2())
break;
refill2 = false;
}

if (compare(input1_top, input2_top)) // input1_top < input2_top
{
output() << input1_top << '\n';
refill1 = true;
}
else
{
output() << input2_top << '\n';
refill2 = true;
}
}

janekb04 marked this conversation as resolved.
Show resolved Hide resolved
// At this point exactly one of the inputs is empty
// and the remaining input from the second one will get outputted
output() << input1().rdbuf() << input2().rdbuf();
}

#endif // AGG_SORT_H
1 change: 1 addition & 0 deletions runtime/agg/cpp/aggregators/sort/agg-linux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "agg-bsd.h"
2 changes: 2 additions & 0 deletions runtime/agg/cpp/tests/test-bsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
./test-common.sh uniq "-c" ../bin/uniq
./test-common.sh uniq "--count" ../bin/uniq

./test-common.sh sort "" ../bin/sort

# These tests are run during PASH_TOP/scripts/run_tests.sh
# Make sure to build the aggregators using PASH_TOP/scripts/setup-pash.sh first
#
Expand Down
2 changes: 2 additions & 0 deletions runtime/agg/cpp/tests/test-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
./test-common.sh uniq "-c" ../bin/uniq
./test-common.sh uniq "--count" ../bin/uniq

./test-common.sh sort "" ../bin/sort

# These tests are run during PASH_TOP/scripts/run_tests.sh
# Make sure to build the aggregators using PASH_TOP/scripts/setup-pash.sh first
#
Expand Down