Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Fastest way to "pick without replacement"

by swl (Priest)
on Nov 20, 2020 at 21:54 UTC ( #11123941=note: print w/replies, xml ) Need Help??


in reply to Re: Fastest way to "pick without replacement"
in thread Fastest way to "pick without replacement"

Using a slice in the delete call will sidestep the for-loop. The map can also be replaced with a slice.

hash_slice => sub { my %ha; @ha{0..$#numbers} = @numbers; delete @ha{@indices}; my @output = @ha{sort keys %ha}; join("\0", @output) eq join("\0", @expect) or die if TEST; },

Replies are listed 'Best First'.
Re^3: Fastest way to "pick without replacement"
by swl (Priest) on Nov 21, 2020 at 03:06 UTC

    The sort should also be numeric.

    hash_slice => sub { my %ha; @ha{0..$#numbers} = @numbers; delete @ha{@indices}; my @output = @ha{sort {$a <=> $b} keys %ha}; join("\0", @output) eq join("\0", @expect) or die if TEST; },

    Update: Although I now see Choroba has already done that in 11123952.

Re^3: Fastest way to "pick without replacement"
by bliako (Prior) on Nov 20, 2020 at 23:53 UTC

    coolz!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2021-04-14 16:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?