in reply to Re: A more efficient sort or heap algorithm...
in thread A more efficient sort or heap algorithm...

I'm still learning about efficiency (obviously), but the benefit of using the hand coded sort was to allow me to have two arrays sorted the same way (but based on the first, if that makes sense), with the second array containing a hash key leading to the data for the corresponding region. I wasn't sure how to implement that using the built in sort function. It allows me to keep track of and print out the information for both regions.
Bioinformatics
  • Comment on Re^2: A more efficient sort or heap algorithm...

Replies are listed 'Best First'.
Re^3: A more efficient sort or heap algorithm...
by przemo (Scribe) on Apr 28, 2009 at 22:51 UTC
    I wasn't sure how to implement that using the built in sort function. It allows me to keep track of and print out the information for both regions.

    Just try to sort the indices and then map both arrays by them:

    my @ind_srtd = sort { $array->[$a] cmp $array->[$b] } (0..$#$array); my @array_srtd = map { $array->[$_] } @ind_srtd; my @array_which_srtd = map { $array_which->[$_] } @ind_srtd;

    I didn't tested it thoroughly, but should look something like this.