From a744a41eacf5e09b44d38011e8aa9dad72fcc294 Mon Sep 17 00:00:00 2001 From: Vicente Adolfo Bolea Sanchez Date: Mon, 16 May 2016 15:38:09 +0900 Subject: [PATCH] Added wc --- src/targets/wc.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/targets/wc.cc diff --git a/src/targets/wc.cc b/src/targets/wc.cc new file mode 100644 index 0000000..4c36ba8 --- /dev/null +++ b/src/targets/wc.cc @@ -0,0 +1,45 @@ +#include "../mapreduce/dataset.hh" + +#include +#include + +using namespace eclipse; +using namespace std; + +extern "C" { + pair myfunc (string); + string myreducer (string, string); +} + +pair myfunc (string a) { + + int total = 0; + char *p = new char[a.length()]; + strncpy (p, a.c_str(), a.length()); + p = strtok(p, " "); + while (p) { + if (p[0] != '\n' or strlen(p) == 0) + total++; + p = strtok(NULL, " "); + } + + delete p; + + auto output = to_string(total); + return {"Total", output}; +} + +string myreducer (string a, string b) { + auto a_ = atoi (a.c_str()); + auto b_ = atoi (b.c_str()); + + auto out = to_string(a_ + b_); + + return out; +} + +int main (int argc, char** argv) { + DataSet& A = DataSet::open(argv[1]); + A.map("myfunc"); + A.reduce("myreducer"); +}