Re: indirect sort
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 12 May 2009 21:13:32 -0700
On Mon, 11 May 2009 19:30:37 -0700 (PDT), tnorgd@xxxxxxxxx wrote,
quoted or indirectly quoted someone who said :
I would like to sort an array of object in respect to one of the
fields, say of type double. I wrote a Comparator (I don't want to use
Comparable in order to be able to choose the field I am sorting by)
and ... it seems to be slow. I checked with profiler and my
Comparator.compare() method takes most of the execution time (well,
this sounds obvious). But I pretty sure that sorting double[] would be
much faster than sorting MyObject[] (and calling compare()). Is there
a way to create a double[] array of my fields I want to sort by, sort
that array and then recover the permutation?
If you sort an array of double vs Double it will sort the data rather
than an array of pointers to the objects. I would expect double to be
faster than Double, the reverse of what you anticipate.
See http://mindprod.com/jgloss/sort.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
"It wasn?t the Exxon Valdez captain?s driving that caused the Alaskan oil spill. It was yours."
~ Greenpeace advertisement New York Times 1990-02-25
.
- References:
- indirect sort
- From: tnorgd
- indirect sort
- Prev by Date: Re: Can someone please clarify what "modern" Java is for me?
- Next by Date: Re: Any java lib. to parse .cab file?
- Previous by thread: Re: indirect sort
- Next by thread: Re: indirect sort
- Index(es):
Relevant Pages
|