The C# library for WebMapReduce is based on two user classes, and uses an iterator to manage the list of values passed to the reducer. The two classes that users must provide are:
namespace WMR {
public class Mapper
{
public void map(string key, string value);
}
}
namespace WMR {
public class Reducer
{
public void reduce(string key, WmrIterator values);
}
}
namespace WMR {
public class Wmr {
public static void emit(string key, string value) {
}
}
}
The Wmr class contains a single method:
namespace WMR {
public class WmrIterator : System.Collections.IEnumerable {
public bool hasNext();
public System.Collections.IEnumerator GetEnumerator();
}
}
The WmrIterator class provides the list of values to the reducer. It also implements the Systems.Collections.IEnumerable interface so that it can be used with the foreach statement of the C# language, which means that one should rarely need to use its methods directly.
namespace WMR {
public class Mapper
{
public void map(string key, string value) {
string[] words = key.Split(' ');
foreach (string word in words) {
Wmr.emit(word, "1");
}
}
}
}
namespace WMR {
public class Reducer
{
public void reduce(string key, WmrIterator values) {
int sum = 0;
foreach (string value in values) {
sum += System.Convert.ToInt32(value);
}
Wmr.emit(key, System.Convert.ToString(sum));
}
}
}