main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | declare class Queue<ValueType> implements Iterable<ValueType> {
|
---|
2 | /**
|
---|
3 | The size of the queue.
|
---|
4 | */
|
---|
5 | readonly size: number;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | Tiny queue data structure.
|
---|
9 |
|
---|
10 | The instance is an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), which means you can iterate over the queue front to back with a “for…of” loop, or use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.
|
---|
11 |
|
---|
12 | @example
|
---|
13 | ```
|
---|
14 | import Queue = require('yocto-queue');
|
---|
15 |
|
---|
16 | const queue = new Queue();
|
---|
17 |
|
---|
18 | queue.enqueue('🦄');
|
---|
19 | queue.enqueue('🌈');
|
---|
20 |
|
---|
21 | console.log(queue.size);
|
---|
22 | //=> 2
|
---|
23 |
|
---|
24 | console.log(...queue);
|
---|
25 | //=> '🦄 🌈'
|
---|
26 |
|
---|
27 | console.log(queue.dequeue());
|
---|
28 | //=> '🦄'
|
---|
29 |
|
---|
30 | console.log(queue.dequeue());
|
---|
31 | //=> '🌈'
|
---|
32 | ```
|
---|
33 | */
|
---|
34 | constructor();
|
---|
35 |
|
---|
36 | [Symbol.iterator](): IterableIterator<ValueType>;
|
---|
37 |
|
---|
38 | /**
|
---|
39 | Add a value to the queue.
|
---|
40 | */
|
---|
41 | enqueue(value: ValueType): void;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | Remove the next value in the queue.
|
---|
45 |
|
---|
46 | @returns The removed value or `undefined` if the queue is empty.
|
---|
47 | */
|
---|
48 | dequeue(): ValueType | undefined;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | Clear the queue.
|
---|
52 | */
|
---|
53 | clear(): void;
|
---|
54 | }
|
---|
55 |
|
---|
56 | export = Queue;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.