-
-
Save samcv/9a65a586ea21b20def8efe4aaaab55de to your computer and use it in GitHub Desktop.
Add a million keys to a hash, then delete every other, add them back. Then delete every 3rd, then add back... up to 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my %hash; | |
my int $num := 1000000; | |
my int $i := 0; | |
while $i < $num { | |
nqp::bindkey(%hash, $i, 1); | |
$i := $i + 1; | |
} | |
my @array := (2, 3, 4, 5, 6); | |
for @array { | |
$i := 0; | |
while $i < $num { | |
nqp::deletekey(%hash, $i); | |
$i := $i + $_; | |
} | |
$i := 0; | |
while $i < $num { | |
nqp::bindkey(%hash, $i, 1); | |
$i := $i + $_; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my %hash; | |
my int $num = 1000000; | |
for ^$num -> $i { | |
%hash{$i} = 1; | |
} | |
my int $i; | |
my @array := (2, 3, 4, 5, 6); | |
for (2, 3, 4, 5, 6) -> $interval { | |
loop ($i = 0; $i < $num; $i += $interval) { | |
%hash{$i}:delete; | |
} | |
loop ($i = 0; $i < $num; $i += $interval) { | |
%hash{$i} = 1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hash = {} | |
num = 1000000 | |
for i in range(num): | |
hash[i] = 1 | |
for j in (2,3,4,5,6): | |
for i in range(0, num, j): | |
del hash[i] | |
for i in range(0, num, j): | |
hash[i] = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment