Skip to content

Instantly share code, notes, and snippets.

@luzhuomi
Created March 8, 2014 14:18
Show Gist options
  • Save luzhuomi/9431203 to your computer and use it in GitHub Desktop.
Save luzhuomi/9431203 to your computer and use it in GitHub Desktop.
int[] a = { 1, 3, 4, 5,12, 3, 8 ,10, 10000, 12003 } ;
int result = 1;// 1 is the identify of the integer product
for ( int i = 0; i <= a.length ; i ++ ) {
result = a[i] * result;
}
return result;
int [] a1 = split(a,5,0);
int [] a2 = split(a,5,1);
// machine 1
int result1 = 1;// 1 is the identify of the integer product
for ( int i = 0; i <= a.length ; i ++ ) {
result1 = a1[i] * result1;
}
return result1;
// machine 2
int result1 = 1;// 1 is the identify of the integer product
for ( int i = 0; i <= a.length ; i ++ ) {
result2 = a2[i] * result2;
}
return result2;
// waiting machine 1 and machine 2 to return me the results.
return result1 * result2;
Hello Hello
Si Hua
map() the first iteration
0, "Hello Hello" -->
{"Hello", "Hello"} -->
{ ("Hello", 1)
("Hello", 1) } ---> ("Hello", {1, 1} ) ---> reducer
{ ("Si", 1) } ---> ("Si", {1} ) ---> reducer
{ ("Hua", 1) } ---> ("Hua", {1}) ---> reducer
reducer()
"Hello", 2
"Si", 1
"Hua", 1
Hello 2
Si 1
Hua 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment