-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreduce.h
More file actions
61 lines (49 loc) · 956 Bytes
/
reduce.h
File metadata and controls
61 lines (49 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include<mutex>
#include<map>
std::string strOne;
std::string *wString = &strOne;
typedef struct
{
std::string Key;
int Val;
} KEYPAIR;
class Reduce
{
public:
Reduce();
~Reduce();
std::vector<KEYPAIR> pairs;
void shuffle(Reduce *reduce,std::map<std::string, int> map ,int dest ) {
KEYPAIR y;
std::unique_lock<std::mutex> lock(mtx);
for (std::map<std::string, int>::iterator it = map.begin(); it != map.end(); ++it) {
y.Key = it->first;
y.Val= it->second;
reduce[dest].pairs.push_back(y);
}
return ;
}
void compute(std::string filename) {
std::ofstream myfile;
myfile.open(filename, std::ios_base::app);
//std::cout << *wString;
myfile << *wString;
myfile.close();
}
bool join(std::string wstr) {
std::unique_lock<std::mutex> lock(mtx_file);
*wString += wstr;
return true;
}
private:
std::mutex mtx;
std::mutex mtx_file;
};
Reduce::Reduce()
{
}
Reduce::~Reduce()
{
}
#pragma once