1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"824.42">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco
; color: #0019b7}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco
; min-height: 16.0px}
17 span
.s1
{text-decoration: underline
}
18 span
.s2
{color: #0019b7}
19 span
.s3
{color: #000000}
20 span
.s4
{color: #316c17}
21 span
.Apple-tab-span
{white-space:pre
}
25 <p class=
"p1"><b>PriorityQueue
</b></p>
26 <p class=
"p2"><br></p>
27 <p class=
"p3"><b>superclass: Object
</b></p>
28 <p class=
"p2"><br></p>
29 <p class=
"p3">PriorityQueue implements a priority queue data structure, which is
</p>
30 <p class=
"p3">used to build schedulers.
</p>
31 <p class=
"p3">It allows you to put in items at some arbitrary time and pop them in
<span class=
"Apple-converted-space"> </span></p>
32 <p class=
"p3">time order.
</p>
33 <p class=
"p2"><br></p>
34 <p class=
"p4"><b><span class=
"s1">Instance Methods:
</span></b></p>
35 <p class=
"p2"><br></p>
36 <p class=
"p3"><b>put(time, item)
</b></p>
37 <p class=
"p2"><br></p>
38 <p class=
"p3">Puts the item in the queue at the given time.
</p>
39 <p class=
"p2"><br></p>
40 <p class=
"p3"><b>topPriority
</b></p>
41 <p class=
"p2"><br></p>
42 <p class=
"p3">Returns the time of the earliest item in the queue.
</p>
43 <p class=
"p2"><br></p>
44 <p class=
"p3"><b>pop
</b></p>
45 <p class=
"p2"><br></p>
46 <p class=
"p3">Returns the earliest item in the queue.
</p>
47 <p class=
"p2"><br></p>
48 <p class=
"p3"><b>clear
</b></p>
49 <p class=
"p2"><br></p>
50 <p class=
"p3">Empty the queue.
</p>
51 <p class=
"p2"><br></p>
52 <p class=
"p3"><b>isEmpty
</b></p>
53 <p class=
"p2"><br></p>
54 <p class=
"p3">Return a Boolean whether the queue is empty.
</p>
55 <p class=
"p2"><br></p>
56 <p class=
"p3"><b>notEmpty
</b></p>
57 <p class=
"p2"><br></p>
58 <p class=
"p3">Return a Boolean whether the queue is not empty.
</p>
59 <p class=
"p2"><br></p>
60 <p class=
"p2"><br></p>
61 <p class=
"p4"><b><span class=
"s1">Example:
</span></b></p>
62 <p class=
"p2"><br></p>
64 <p class=
"p5"><span class=
"s2">var
</span> p;
</p>
65 <p class=
"p6"><span class=
"s3">p =
</span>PriorityQueue
<span class=
"s3">.new;
</span></p>
66 <p class=
"p7"><br></p>
67 <p class=
"p5">p.put(
0.1,
<span class=
"s4">\a
</span>);
</p>
68 <p class=
"p5">p.put(
2.0,
<span class=
"s4">\b
</span>);
</p>
69 <p class=
"p5">p.put(
0.5,
<span class=
"s4">\c
</span>);
</p>
70 <p class=
"p5">p.put(
0.2,
<span class=
"s4">\d
</span>);
</p>
71 <p class=
"p5">p.put(
1.0,
<span class=
"s4">\e
</span>);
</p>
72 <p class=
"p7"><br></p>
73 <p class=
"p5">while ({ p.notEmpty },{
</p>
74 <p class=
"p5"><span class=
"Apple-tab-span"> </span>[p.topPriority, p.pop].postln;
</p>
76 <p class=
"p7"><br></p>
77 <p class=
"p7"><br></p>
78 <p class=
"p5">p.pop.postln;
</p>
79 <p class=
"p5">p.pop.postln;
</p>
80 <p class=
"p5">p.pop.postln;
</p>
81 <p class=
"p7"><br></p>
83 <p class=
"p7"><br></p>
84 <p class=
"p5">[
0.1, a ]
</p>
85 <p class=
"p5">[
0.2, d ]
</p>
86 <p class=
"p5">[
0.5, c ]
</p>
87 <p class=
"p5">[
1, e ]
</p>
88 <p class=
"p5">[
2, b ]
</p>
92 <p class=
"p7"><br></p>
93 <p class=
"p7"><br></p>