8. C# Library

8.1. Overview

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);
  }
}

8.2. API

8.2.1. Class Wmr

namespace WMR {
  public class Wmr {
    public static void emit(string key, string value) {
    }
  }

}

The Wmr class contains a single method:

public static void emit(string, string)
Prints the two provided string objects to standard output separated by a tab character.

8.2.2. Class WmrIterator

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.

public bool hasNext()
Returns true when there is at least one additional value contained in the list (standard input) managed by the iterator. Otherwise returns false.
public Systems.Collections.IEnumerator GetEnumerator()
Returns a C# enumerator that iterates through the input and can be used with foreach.

8.3. Example Usage

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));
    }
  }
}

Table Of Contents

Previous topic

7. Java Library

Next topic

EC2 Guide

This Page