Re: indirect sort



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
.



Relevant Pages

  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)
  • A Fast sorting algorithm for almost sorted data
    ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ... public class RunSort implements Comparator ... public static void sort(Comparable a, int start,int end) ...
    (comp.compression)
  • Re: Sorting routine
    ... n RSHIFT shifts n bits. ... in the output array. ... This would be handy for sign sorting of 2's complement. ... So Radix/Distribution sort is about 1.4 times faster than Sedge's Sort. ...
    (comp.lang.forth)
  • Re: Sorting objects in ooRex? is this possible with data structures?
    ... The sorting features are modeled off of what Java does with its Comparable and Comparator classes. ... If you want to sort on different column positions, we have a Comparator class that allows you to specify the comparison colums. ... Here's one that compares strings as numbers: ...
    (comp.lang.rexx)
  • Re: Efficiently Extracting Identical Values From A List/Array
    ... struct SortHelper ... Now sort that array according to NodeIndex: ... running through the data structure and sorting things out. ...
    (comp.lang.cpp)