Extending Java Arrays/Collection Sort API

Doug Lea dl at cs.oswego.edu
Tue Nov 20 12:17:35 UTC 2018


On 11/20/18 2:50 AM, Laurent Bourgès wrote:
> Hi,
> Any feedback on improving Java Sort API ?

I think most considerations await progress on value types. I posted some
ideas and links to code last summer on Valhalla list:
http://mail.openjdk.java.net/pipermail/valhalla-dev/2018-August/thread.html

They didn't include APIs for sorting based on indexes, which I agree
should be considered. However, until value types arrive, it would be
hard to justify adding variants for each primitive type.

Almost every sorting algorithm is best for some data types and inputs.
And there are a lot of algorithms. Among the hard choices for JDK is to
pick a small a only a few (stable vs nonstable, parallelizable, etc),
that together provide good choices for most usages. Even then, some
usages (possibly including the one in your initial post) might be better
off creating a custom solution. (As is true for all JDK
Collections/Array-related components.)

-Doug


>     What about an Arrays API extension:
>     - Arrays.sort(int[] a, int[] b, low, high) or
>     Indices int[] Arrays.sortIndices(int[] a, low high), a[] left untouched
>     - same with preallocated buffers & runs arrays
>     - alternatively, it could be expressed as Comparator<Primitive>
>     Arrays.sort(int[] a, low, high, Comparator<int, int> cmp) that sorts
>     array a using the given comparator. For example, a[] could be edge
>     indices sorted according to their edge x position...
>     This comparator is specific as it compares anything (external
>     storage) at given indices i,j.
> 



More information about the core-libs-dev mailing list