Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by salva (Abbot)
on Nov 26, 2009 at 11:40 UTC ( #809539=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://809539]
help
Chatterbox?
[Discipulus]: found translate only good from or possibly to english.. in any other case i use double way translation

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2018-06-19 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (111 votes). Check out past polls.

    Notices?