Yu Kobayashi
2015-02-23 17:21:51 UTC
Hello.
http://jira.codehaus.org/browse/GROOVY-7319
I want to add min() and max() to primitive arrays.
https://github.com/groovy/groovy-core/pull/616
and it is very slow.
https://github.com/yukoba/groovy-core/blob/PrimitiveArrayMinMax/src/main/groovy/util/function/IntComparator.java
So I want to add int[].min(IntComparator)
IntComparator is
int compare(int v1, int v2).
java.util.Comparator is
int compare(T o1, T o2).
As Java 8 puts those methods in java.util.function package,
I put them in groovy.util.function package.
I can use like this.
def ary = [-1, -2, -3] as int[]
ary.min { int a, int b -> -a <=> -b }
I noticed the following problem when I am writing this e-mail.
One big problem of this way is
I am ignoring one argument version of Iterable.min(Closure).
One solution is to add two methods instead of min().
ary.minCompare { int a, int b -> -a <=> -b }
ary.minApply { int v -> -v }
I have to add groovy.util.function.IntUnaryOperator for minApply().
Another solution is to add two argument types.
ary.min({ int a, int b -> -a <=> -b } as IntComparator})
ary.min({ int v -> -v } as IntUnaryOperator})
I don't like this one because this is complicated.
Are there any other problems?
http://jira.codehaus.org/browse/GROOVY-7319
I want to add min() and max() to primitive arrays.
https://github.com/groovy/groovy-core/pull/616
Then there is of course the course of action regarding those primitive type comparators. Maybe that should be discussed on the mailing list instead of here
Iterable.min(Comparator) have to create Integer instance every timeand it is very slow.
https://github.com/yukoba/groovy-core/blob/PrimitiveArrayMinMax/src/main/groovy/util/function/IntComparator.java
So I want to add int[].min(IntComparator)
IntComparator is
int compare(int v1, int v2).
java.util.Comparator is
int compare(T o1, T o2).
As Java 8 puts those methods in java.util.function package,
I put them in groovy.util.function package.
I can use like this.
def ary = [-1, -2, -3] as int[]
ary.min { int a, int b -> -a <=> -b }
I noticed the following problem when I am writing this e-mail.
One big problem of this way is
I am ignoring one argument version of Iterable.min(Closure).
One solution is to add two methods instead of min().
ary.minCompare { int a, int b -> -a <=> -b }
ary.minApply { int v -> -v }
I have to add groovy.util.function.IntUnaryOperator for minApply().
Another solution is to add two argument types.
ary.min({ int a, int b -> -a <=> -b } as IntComparator})
ary.min({ int v -> -v } as IntUnaryOperator})
I don't like this one because this is complicated.
Are there any other problems?
--
Yu Kobayashi <***@gmail.com>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Yu Kobayashi <***@gmail.com>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email