1 public class MapReduceBase {
3 public static void map(String key, String value, OutputCollector output) {
4 int n = value.length();
5 for (int i = 0; i < n; ) {
6 // Skip past leading whitespace
7 while ((i < n) && isspace(value.charAt(i))) {
13 while ((i < n) && !isspace(value.charAt(i))) {
18 output.emit(value.subString(start, i), "1");
19 //System.printString(value.subString(start,i) + "\n");
24 public static void reduce(String key, Vector values, OutputCollector output) {
25 // Iterate over all entries with the
26 // // same key and add the values
28 for(int i = 0; i < values.size(); ++i) {
29 value += Integer.parseInt((String)values.elementAt(i));
32 // Emit sum for input->key()
33 output.emit(key, String.valueOf(value));
36 static boolean isspace(char c) {