1 public class MapWorker {
11 OutputCollector output;
14 OutputCollector[] outputs;
16 public MapWorker(String key, String value, int r, int id) {
22 this.output = new OutputCollector();
24 /*locations = new String[r];
25 for(int i = 0; i < r; ++i) {
26 StringBuffer temp = new StringBuffer("/scratch/mapreduce_nor/output-intermediate-map-");
27 temp.append(String.valueOf(ID));
29 temp.append(String.valueOf(r));
31 temp.append(String.valueOf(i));
33 locations[i] = new String(temp);
36 outputs = new OutputCollector[r];
37 for(int i = 0; i < r; ++i) {
43 MapReduceBase.map(key, value, output);
46 public void partition() {
47 int size = this.output.size();
48 for(int i = 0; i < size; ++i) {
49 String key = this.output.getKey(i);
50 String value = this.output.getValue(i);
51 // use the hashcode of key to decide which intermediate output
52 // this pair should be in
53 int index = (int)Math.abs(key.hashCode()) % this.r;
54 OutputCollector oStream = outputs[index];
57 oStream = new OutputCollector(); // append
58 outputs[index] = oStream;
60 oStream.emit(key, "1");
64 public OutputCollector outputFile(int i) {