in reply to Perl 6 sorting (was: Re: Sort: By keys, values, and their returning values.)
in thread Sort: By keys, values, and their returning values.

Having Pair objects and a built-in Schwartzian transform makes sorting really simple and powerful

I hope you are not really using the Schwartzian transform in Rakudo as it is one of the worst ways to optimize a sort-by-generated-key operation!

Something as...

@keys = map gen_key($_), @data; @sorted = @data[sort {$keys[$a] <=> $keys[$b]} 0..$#keys];
should perform much better when correctly implemented in a low level language, specially if you are able to use packed arrays to store @keys.
  • Comment on Re: Perl 6 sorting (was: Re: Sort: By keys, values, and their returning values.)
  • Download Code

Replies are listed 'Best First'.
Re^2: Perl 6 sorting (was: Re: Sort: By keys, values, and their returning values.)
by moritz (Cardinal) on Nov 26, 2009 at 12:37 UTC
    I hope you are not really using the Schwartzian transform in Rakudo as it is one of the worst ways to optimize a sort-by-generated-key operation!

    Actually it's an implementation detail about which I don't care really much. Correctness first, performance later. I just called it a Schwartzian Transform because that's the name that most perl programmers use for the sort-by-generated-key operation.

    Looking at the source it seems to do something close to what you proposed.

    Perl 6 - links to (nearly) everything that is Perl 6.