in reply to Parallel Array Sorting

See fast, flexible, stable sort. I've translated your code using that idea.

sub parasort { my $sort = shift; my $independent_array = shift; my @dependent_arrays = @_; my @sort_ix = map unpack( 'N', substr( $_, -4 ) ), sort map &$sort( $independent_array->[ $_ ] ) . pack( 'N', $_ ), 0 .. $#$independent_array; return map [ @{ $_ }[ @sort_ix ] ], $independent_array, @dependent_arrays ; }

Replies are listed 'Best First'.
Re: Re: Parallel Array Sorting
by simonm (Vicar) on May 04, 2004 at 16:51 UTC
    This is indeed faster, but it should be noted that the meaning of the code-ref that's passed in is quite different than in the OP... Rather than being a sort function, this version uses the code-ref as a transform used to convert the source values into a bytewise-sortable format. This can be a big performance win, as has been discussed elsewhere, but does require a bit of fiddling to be convert the calling code from the approach used by the OP.