Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,14 +1,13 @@
class PriorityQueue {
has @!tasks is rw;
has @!tasks;
method insert ( Int $priority where { $priority >= 0 }, $task ) {
@!tasks[$priority] //= [];
method insert (Int $priority where * >= 0, $task) {
@!tasks[$priority].push: $task;
}
method get { @!tasks.first({$^_}).shift }
method get { @!tasks.first(?*).shift }
method is_empty { !?@!tasks.first({$^_}) }
method is-empty { ?none @!tasks }
}
my $pq = PriorityQueue.new;
@ -26,4 +25,4 @@ for (
$pq.insert( $priority, $task );
}
say $pq.get until $pq.is_empty;
say $pq.get until $pq.is-empty;