The C libraries for WebMapReduce expect the mapper and the reducer to be defined by two methods with the following signatures:
void mapper(char* key, char* val);
void reducer(char* key, wmr_handle handle);
One should also include the file “wmr.h”
The wmr.h file provides the following types and functions:
typedef const int wmr_handle;
void wmr_emit(const char* key, const char* val);
const char* wmr_get_val(wmr_handle h);
#include <string.h>
#include "wmr.h"
void mapper(char* key, char* val) {
while (key != NULL) {
wmr_emit(strsep(&key, " "), "1");
}
}
#include "wmr.h"
#include <stdlib.h>
void reducer(char* key, wmr_handle handle) {
long sum = 0; /* sum of values encountered so far */
char *str; /* to hold string representation of an integer value */
char sumstr[20]; /* to hold string representation of sum */
while (str = wmr_get_val(handle))
sum += strtol(str, NULL, 10);
sprintf(sumstr, "%d", sum);
wmr_emit(key, sumstr);
}