commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <>
Subject Re: [math] Add Pair factory method, toString(), Comparator
Date Wed, 16 Oct 2013 20:56:06 GMT
On Wed, 16 Oct 2013 09:57:52 +0100, Sean Owen wrote:
> On Wed, Oct 16, 2013 at 9:52 AM, Gilles 
> <>wrote:
>>  I think the Comparator can also replace a
>>> custom one in MathArrays.
>> Are you sure?
> Yes, at least tests pass. There are two anonymous comparator classes 
> there
> which compare by key. The new Comparator compares by key too (and by 
> value,
> but this shouldn't hurt as the current code doesn't care about 
> ordering
> among pairs with the same key). Collections.reverseOrder() can be 
> used to
> reverse the Comparator too.

The potential problem is performance. The current code for 
"sortInPlace" is
not as fast as it could be, very probably because it uses a Comparator. 
using your new comparator will add another "if" (to test whether 
comparing the
"value"s is necessary). [And "reverseOrder" will also add a few 
operations on
its own, I guess.]
It would be nice to know whether the impact is really fairly 
negligible, or

There is a class (in the "test" part of repository) for performing 
that tries to provide fair comparison results by interleaving calls to 
(or more) alternative codes.

Best regards,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message