-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33db5ab
commit a744a41
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |