Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Noodling with natural sorting in perl6

by eric256 (Parson)
on Aug 20, 2010 at 16:57 UTC ( #856324=note: print w/ replies, xml ) Need Help??


in reply to Noodling with natural sorting in perl6

I played around and it seems that creating the copies is where a lot of time is lost in the second version causeing it to be slow. So i moved the processing out of the map and into a function, the cached results out of it, and used that for the sort. Makes it appear about the same speed as the first sort, not positive the best way to benchmark in perl6 yet though.

my %cache; sub pre_process($word) { unless %cache.exists($word) { %cache{$word} = $word.subst(/(\d+)/, -> $/{ sprintf( "%s%c%s", +0 , $0.chars, $0)}, :g).lc; } return %cache{$word}; } sub natural_cmp ($a, $b) { return (pre_process($a) cmp pre_process($b)); }

___________
Eric Hodges


Comment on Re: Noodling with natural sorting in perl6
Download Code
Re^2: Noodling with natural sorting in perl6
by thundergnat (Deacon) on Aug 20, 2010 at 18:12 UTC

    A very nice modification, one that should have been obvious to me in retrospect. You're basically implementing an orcish maneuver

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://856324]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-07-26 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls