-
Notifications
You must be signed in to change notification settings - Fork 17
/
queue.ts
46 lines (40 loc) · 1.09 KB
/
queue.ts
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
/**
* A queue holds elements until they are read. The order in which elements are
* read is determined by the implementation of the queue.
*/
export interface Queue<E> {
/**
* Adds an element to the queue.
* @param element the element to add
*/
add(element: E): void;
/**
* Clears the queue, removing all elements.
*/
clear(): void;
/**
* Calls the given function for each element in the queue.
* @param fn the function to call
*/
forEach(fn: (element: E) => unknown): void;
/**
* Number of elements in the queue.
* @return the number of elements in the queue
*/
length(): number;
/**
* Whether the queue is empty.
* @return true if the queue is empty, false otherwise
*/
isEmpty(): boolean;
/**
* Returns the next element in the queue without removing it.
* @return the next element in the queue, or undefined if the queue is empty
*/
peek(): E | undefined;
/**
* Removes and returns the next element in the queue.
* @return the next element in the queue, or undefined if the queue is empty
*/
read(): E | undefined;
}