T
tnorgd
Dear Group,
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?
For example GNU Scientific Library has a method gsl_heapsort_index()
which doesn't actually sort a given array, but creates a permutation
(which is of a type int[]) which says what is order of my objects to
make them sorted. I think this is exactly what I need. Do I have to
write it on my own or somebody has already did it?
Best regards,
Dominik
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?
For example GNU Scientific Library has a method gsl_heapsort_index()
which doesn't actually sort a given array, but creates a permutation
(which is of a type int[]) which says what is order of my objects to
make them sorted. I think this is exactly what I need. Do I have to
write it on my own or somebody has already did it?
Best regards,
Dominik