Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [collections-dev] Sort primitives with a comparator

Ref: http://stackoverflow.com/questions/4859261/get-the-indices-of-an-array-after-sorting

All the solutions presented require boxing integers.

On Thu, Mar 23, 2017 at 12:16 AM, Motlin, Craig P. <Craig.Motlin@xxxxxx> wrote:

Thank you!

 

In my own experience, I've needed just two orderings, ascending and descending according to the natural order. For descending order, I need an extra step.

 

mutableIntList.sortThis().reverseThis();

 

I'm curious about your use-case if you can share more details. I suppose it could be useful to sort numbers by their absolute value or something similar.

 

Unfortunately, we can't integrate an implementation derived from GPL code. That problem aside, I think this is a good idea and can make a great contribution.

 

From: collections-dev-bounces@eclipse.org [mailto:collections-dev-bounces@xxxxxxxxxxx] On Behalf Of Kevin Connor Arpe
Sent: Wednesday, March 22, 2017 12:04 PM
To: collections-dev@xxxxxxxxxxx
Subject: [collections-dev] Sort primitives with a comparator

 

Hello,

 

I recently started using GS/Eclipse collections.  It is like a breath of fresh air.  Thank you for all of your hard work.

 

In the primitive collections, such as MutableIntList, I see a sortThis() method.  I looked at the impl and I see it calls Arrays.sort() directly on the underlying array.  I did not see a version that takes a primitive comparator.

 

It has always been a sore spot with me that Java does not natively support Arrays.sort(<PrimitiveArray>, <PrimitiveComparator>).

 

I was considering to derive from the TimSort that Java 8 uses and contribute, but I don't know if there is a license conflict.  If GPL2 + linking exception doesn't work, is there another impl of sorting for generics that can easily be adapted for primitives?

 

Finally, I looked at the Java 8 impl for primitive array sorting.  Adapting that code to accept a primitive comparator looks much more challenging.

 

Kindly let me know what you think.

 

Thanks,

Arpe

Hongkong


_______________________________________________
collections-dev mailing list
collections-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/collections-dev



Back to the top