Brunet.Services.MapReduce.MapReduceRangeCounter.Reduce C# (CSharp) Method

Reduce() public method

public Reduce ( Channel q, object reduce_arg, object current_result, RpcResult child_rpc ) : void
q Brunet.Concurrent.Channel
reduce_arg object
current_result object
child_rpc Brunet.Messaging.RpcResult
return void
    public override void Reduce(Channel q, object reduce_arg, 
                                  object current_result, RpcResult child_rpc) {

      bool done = false;
      //ISender child_sender = child_rpc.ResultSender;
      //the following can throw an exception, will be handled by the framework
      object child_result = child_rpc.Result;
      
      //child result is a valid result
      if (current_result == null) {
        q.Enqueue(new Brunet.Collections.Pair<object, bool>(child_result, done));
        return;
      }
      
      IDictionary my_entry = current_result as IDictionary;
      IDictionary value = child_result as IDictionary;
      int max_height = (int) my_entry["height"];
      int count = (int) my_entry["count"];

      int y = (int) value["count"];
      my_entry["count"] = count + y;
      int z = (int) value["height"] + 1;
      if (z > max_height) {
        my_entry["height"] = z; 
      }
      q.Enqueue(new Brunet.Collections.Pair<object, bool>(my_entry, done));
    }
  }