-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReduceWorker.java
More file actions
49 lines (43 loc) · 1.18 KB
/
ReduceWorker.java
File metadata and controls
49 lines (43 loc) · 1.18 KB
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
import java.util.HashMap;
public class ReduceWorker extends Thread{
WorkPool reduceWp, compareWp;
private HashMap<String, HashMap<String, Integer> > docHash;
public ReduceWorker(WorkPool workpool, WorkPool compareWp) {
this.reduceWp = workpool;
this.compareWp = compareWp;
docHash = new HashMap<String, HashMap<String, Integer>>();
}
void processPartialSolution(ReduceTask task) {
String docName = task.getDocumentName();
if (docHash.containsKey(docName)) {
;
}
else {
docHash.put(docName, new HashMap<String, Integer>());
}
for (String key : task.getHash().keySet()) {
if (docHash.get(docName).containsKey(key)) {
docHash.get(docName).put(key, docHash.get(docName).get(key) + task.getHash().get(key));
}
else {
docHash.get(docName).put(key, task.getHash().get(key));
}
}
}
public HashMap<String, HashMap<String, Integer> > getHash()
{
return docHash;
}
@Override
public void run() {
//System.out.println("Thread-ul worker " + this.getName() + " a pornit...");
ReduceTask task;
while (true) {
task = (ReduceTask)reduceWp.getWork();
if (task == null){
break;
}
processPartialSolution(task);
}
}
}