68 lines
1.1 KiB
Text
68 lines
1.1 KiB
Text
|
CLASS::PriorityQueue
|
||
|
summary:: Priority queue data structure
|
||
|
categories:: Collections>Ordered
|
||
|
|
||
|
DESCRIPTION::
|
||
|
PriorityQueue implements a priority queue data structure, which is used to build schedulers. It allows you to put in items at some arbitrary time and pop them in
|
||
|
time order.
|
||
|
|
||
|
INSTANCEMETHODS::
|
||
|
private::prInternalArray
|
||
|
|
||
|
|
||
|
method::put
|
||
|
Puts the item in the queue at the given time.
|
||
|
|
||
|
method::topPriority
|
||
|
Returns the time of the earliest item in the queue.
|
||
|
|
||
|
method::pop
|
||
|
Returns the earliest item in the queue.
|
||
|
|
||
|
method::clear
|
||
|
Empty the queue.
|
||
|
|
||
|
method::isEmpty
|
||
|
Return a link::Classes/Boolean:: whether the queue is empty.
|
||
|
|
||
|
method::notEmpty
|
||
|
Return a link::Classes/Boolean:: whether the queue is not empty.
|
||
|
|
||
|
method::removeValue
|
||
|
Remove all instances of value from the queue.
|
||
|
|
||
|
|
||
|
EXAMPLES::
|
||
|
|
||
|
code::
|
||
|
(
|
||
|
var p;
|
||
|
p = PriorityQueue.new;
|
||
|
|
||
|
p.put(0.1, \a);
|
||
|
p.put(2.0, \b);
|
||
|
p.put(0.5, \c);
|
||
|
p.put(0.2, \d);
|
||
|
p.put(1.0, \e);
|
||
|
|
||
|
while ({ p.notEmpty },{
|
||
|
[p.topPriority, p.pop].postln;
|
||
|
});
|
||
|
|
||
|
|
||
|
p.pop.postln;
|
||
|
p.pop.postln;
|
||
|
p.pop.postln;
|
||
|
|
||
|
)
|
||
|
|
||
|
[ 0.1, a ]
|
||
|
[ 0.2, d ]
|
||
|
[ 0.5, c ]
|
||
|
[ 1, e ]
|
||
|
[ 2, b ]
|
||
|
nil
|
||
|
nil
|
||
|
nil
|
||
|
::
|