Skip to content

Commit

Permalink
Added wc
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentebolea committed May 16, 2016
1 parent 33db5ab commit a744a41
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/targets/wc.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "../mapreduce/dataset.hh"

#include <utility>
#include <string>

using namespace eclipse;
using namespace std;

extern "C" {
pair<string, string> myfunc (string);
string myreducer (string, string);
}

pair<string, string> 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");
}

0 comments on commit a744a41

Please sign in to comment.