/**
  *  The mapper algorithm starts by calling the map() function in your class
  *  for every input value that you send to your mapper.
  *
  *  In this WordCount example the input value is a string with a file name.
  *  This name is relative to the GlusterFS mount point.
  *
  *  @param  mixed       Value that is being mapped (in this example: a path)
  *  @param  Reducer     Reducer object to which we may emit key/value pairs
  */
 function map($key, $value, Yothalot\Reducer $reducer)
 {
     // the value is a filename that we can open
     if (!is_resource($fp = fopen($value, "r"))) {
         throw new Exception("Unable to open " . $value);
     }
     // read one line at a time (this implementation is scalable, only one
     // line is being read, so that the script never has to use a lot of
     // memory to load the entire file)
     while (($line = fgets($fp)) !== false) {
         $reducer->emit($value, 1);
     }
     // close the file
     fclose($fp);
 }
 /**
  *  The mapper algorithm starts by calling the map() function in your class
  *  for every input value that you send to your mapper.
  *
  *  In this WordCount example the input value is a string with a file name.
  *  This name is relative to the GlusterFS mount point.
  *  @param  mixed       The key that is being mapped, in this example an empty string
  *  @param  mixed       Value that is being mapped (in this example: a path)
  *  @param  Reducer     Reducer object to which we may emit key/value pairs
  */
 public function map($key, $value, Yothalot\Reducer $reducer)
 {
     // the value is a filename that we can open
     if (!is_resource($fp = fopen($value, "r"))) {
         throw new Exception("Unable to open " . $value);
     }
     // read one line at a time (this implementation is scalable, only one
     // line is being read, so that the script never has to use a lot of
     // memory to load the entire file)
     while (($line = fgets($fp)) !== false) {
         // split line in words, and for each word emit key/value pair:
         // the word is the key, the value the number of times the word was seen
         foreach (explode(" ", trim($line)) as $word) {
             $reducer->emit($word, 1);
         }
     }
     // close the file
     fclose($fp);
 }
 /**
  *  The mapper algorithm starts by calling the map() function in your class
  *  for every input value that you send to your mapper.
  *
  *  In this WordCount example the input value is a string with a file name.
  *  This name is relative to the GlusterFS mount point.
  *
  *  @param  mixed       Value that is being mapped (in this example: a path)
  *  @param  Reducer     Reducer object to which we may emit key/value pairs
  */
 function map($key, $value, Yothalot\Reducer $reducer)
 {
     // immediately emit again
     $reducer->emit($key, $value);
 }