Reducing reduce (original) (raw)

Paul Sandoz paul.sandoz at oracle.com
Mon Feb 11 09:43:09 PST 2013


On Feb 11, 2013, at 6:12 PM, Brian Goetz <brian.goetz at Oracle.COM> wrote:

Thanks, Joe. I knew I was missing some use cases. This is definitely a case where the fused version is more efficient, since it can elide some work based on the previous comparison state.

And efficiency wise it would be nice to avoid the boxed().

Paul.

On 2/11/2013 11:57 AM, Joe Bowbeer wrote:

My parallel string-compare sample provides two implementations (below).

Will both of these survive your changes? bitbucket.org/joebowbeer/stringcompare <http://bitbucket.org/joebowbeer/stringcompare> int compareMapReduce(String s1, String s2) { assert s1.length() == s2.length(); return intRange(0, s1.length()).parallel() .map(i -> compare(s1.charAt(i), s2.charAt(i))) .reduce(0, (l, r) -> (l != 0) ? l : r); } int compareBoxedReduce(String s1, String s2) { assert s1.length() == s2.length(); return intRange(0, s1.length()).parallel().boxed() .reduce(0, (l, i) -> (l != 0) ? l : compare(s1.charAt(i), s2.charAt(i)), (l, r) -> (l != 0) ? l : r); }



More information about the lambda-libs-spec-observers mailing list