/mini-map-reduce-js

Reformulation of algorithms for model of MapReduce computations (using handwritten toy MapReduce framework).

Primary LanguageJavaScript

map-reduce-matrix-multiplication-js

Example: Words Count

Let's implement classical example of MapReduce computations model: counting words via MapReduce.

  1. Use mapReduce function from: https://github.com/lagodiuk/mini-map-reduce-js/blob/master/map-reduce.js
  2. Map function:
function map(row, emit) {
  var words = row.split(' ');
  for(var i in words) {
    var word = words[i];
    emit(word, 1);
  }
}
  1. Reduce function:
function reduce(key, values, output) {
  var totalCount = 0;
  for(var i in values) {
    totalCount += values[i];
  }
  output(key + ' -> ' + totalCount);
}
  1. Lets calculate words:
var input = [
  "hello world",
  "hello map reduce",
  "map map"
];
var wordsCount = mapReduce(input, map, reduce);;
  1. wordsCount will be:
[
  "hello -> 2",
  "world -> 1",
  "map -> 3",
  "reduce -> 1"
] 

(see: https://github.com/lagodiuk/mini-map-reduce-js/blob/master/words-count.js)

Matrixes Multiplication

Prototype of 2-step MapReduce algorithm for matrix multiplication

Description of algorithm was found here: http://importantfish.com/two-step-matrix-multiplication-with-hadoop/