in reply to Parallel Array Sorting

This appears to be around twice as fast with your sample data, and should be even faster for larger arrays:
sub fast_parasort (&@) { my($coderef, $master_array, @arrayrefs) = @_; my @indexes = sort { local ($a, $b) = ( $master_array->[$a], $mast +er_array->[$b] ); &$coderef } ( 0 .. $#$master_array ); map { [ @$_[ @indexes ] ] } ( $master_array, @arrayrefs ); }

The biggest distinction is that it avoids creating intermediate hashes and arrays -- instead, it just figures out the sorted order of the indices, based on your first array, and then uses slices to return the sorted version of all of the arrays.

Replies are listed 'Best First'.
Re: Re: Parallel Array Sorting
by Gunth (Scribe) on May 04, 2004 at 22:48 UTC
    Wow, I knew there had to be a much easier way. Thank you very much. This is some very nice code. I could never write this. If this is just twice as fast, it's about a million times cleaner. Thanks again.
    -Will