-
Notifications
You must be signed in to change notification settings - Fork 1
/
Queue.mon
51 lines (48 loc) · 941 Bytes
/
Queue.mon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.apamax.containers;
/**
* A First-In-First-Out queue object.
*/
event Queue
{
/** Create an empty queue. */
static action create() returns Queue
{
return new Queue;
}
/** Push a value onto the back of the queue.
* @param val The value to add to the queue.
*/
action push(any val)
{
data.append(val);
}
/** Remove and return the value on the front of the queue. */
action pop() returns any
{
any val := data[0];
data.remove(0);
return val;
}
/** Return the front value on the queue without removing it. */
action peekNext() returns any
{
return data[0];
}
/** Return the number of items in the queue. */
action size() returns integer
{
return data.size();
}
/** Return true if the queue is empty. */
action empty() returns boolean
{
return data.size()=0;
}
/** Remove all the contents of the queue. */
action clear()
{
data.clear();
}
/** @private */
sequence<any> data;
}