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 all commits
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
3 changes: 3 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Code of Conduct

* [PaSh Code of Conduct](https://github.com/binpash/admin/blob/main/CODE_OF_CONDUCT.md)
2 changes: 1 addition & 1 deletion compiler/parser/libdash
Submodule libdash updated 1 files
+7 −22 ocaml/ast.ml
2 changes: 1 addition & 1 deletion runtime/agg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Let's assume that the aggregator being implemented is for a command called `cmd`

2. For each `OS` supported by PaSh:

2.1 Create a file named `OS-agg.h` inside that folder
2.1 Create a file named `agg-OS.h` inside that folder

2.2. Implement the aggregator inside that file using the instructions provided in `cpp/common/main.h` or use a different aggregator as an example. Remember about the include guard.

Expand Down
62 changes: 62 additions & 0 deletions runtime/agg/cpp/aggregators/sort/agg-bsd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#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 invalid1 = true, invalid2 = true;
while (true)
{
if (invalid1)
{
std::getline(input1(), input1_top);
if (!input1())
break;
invalid1 = false;
}
if (invalid2)
{
std::getline(input2(), input2_top);
if (!input2())
break;
invalid2 = false;
}

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

janekb04 marked this conversation as resolved.
Show resolved Hide resolved
if(!invalid1)
output() << input1_top << '\n';
if(!invalid2)
output() << input2_top << '\n';

// At this point at least one of the inputs
// is empty, so the other one can sefely be forwarded
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