in reply to Re^2: Sorting a hash of arrays based on a particular array element.
in thread Sorting a hash of arrays based on a particular array element.

Wow, most impressive. How do you do the sorting under the covers, can you point me to some online resources ? As it is so much faster than perl's sort will it ever make it into core and replace the current sort or does it gain speed by having different interfaces for sorting different data types ?

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!
  • Comment on Re^3: Sorting a hash of arrays based on a particular array element.

Replies are listed 'Best First'.
Re^4: Sorting a hash of arrays based on a particular array element.
by salva (Canon) on Jul 28, 2005 at 10:10 UTC
    well, actually Sort::Key uses the internal perl sort function under the hood. It just exposes a different API that can cover most sorting usages without incurring in an extra cost as core sort does.

    The algorithm used is similar to...

    sub sortkey { my ($func, @v); my @keys = map { &$func } @v; my @ix = sort { $keys[$a] cmp $keys[$b] } 0..$#keys; return @v[@ix] }
    but being implemented in C (specially, the comparing callbacks) it doesn't require the nasty hacks of the GRT to do the sort part efficiently.