Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Apparently fix "take" failure on JVM
  • Loading branch information
lizmat committed Oct 20, 2014
1 parent 3975e16 commit f0efc88
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/core/Baggy.pm
Expand Up @@ -159,20 +159,18 @@ my role Baggy does QuantHash {
my Int $seen;
my int $todo = ($keep ?? $count !! ($total min $count)) + 1;

gather {
while $todo = $todo - 1 {
$rand = $total.rand.Int;
$seen = 0;
for @pairs -> $pair {
next if ( $seen += $pair.value ) <= $rand;
gather while $todo = $todo - 1 {
$rand = $total.rand.Int;
$seen = 0;
for @pairs -> $pair {
next if ( $seen += $pair.value ) <= $rand;

take $pair.key;
last if $keep;
take $pair.key;
last if $keep;

$pair.value--;
$total = $total - 1;
last;
}
$pair.value--;
$total = $total - 1;
last;
}
}
}
Expand All @@ -182,15 +180,13 @@ my role Baggy does QuantHash {
my Int $rand;
my Int $seen;

gather {
loop {
$rand = $total.rand.Int;
$seen = 0;
for @pairs -> $pair {
next if ( $seen += $pair.value ) <= $rand;
take $pair.key;
last;
}
gather loop {
$rand = $total.rand.Int;
$seen = 0;
for @pairs -> $pair {
next if ( $seen += $pair.value ) <= $rand;
take $pair.key;
last;
}
}
}
Expand Down

0 comments on commit f0efc88

Please sign in to comment.