Represents a queue collection of elements. A queue allows elements to be
added to the end and removed from the front, adhering to the FIFO
(First In, First Out) principle. This interface extends the Collection
interface
and specifies additional queue-specific operations.
Queues are commonly used in scenarios where you need to process elements in the order they were added, such as task scheduling, buffering data streams, and breadth-first graph traversal.
Name |
---|
V |
-
Collection
<number
,V
>↳
Queue
↳↳
Deque
• get
[toStringTag](): string
A string tag for the Collection
class that is used in Object.prototype.toString
.
string
Collection.[toStringTag]
• get
size(): number
Gets the number of elements contained in the Collection
.
number
Collection.size
▸ [iterator](): IterableIterator
<V
>
Returns the default iterator through the queue's elements.
IterableIterator
<V
>
▸ clear(): void
Removes all elements from the Collection
, effectively resetting it.
void
▸ entries(): IterableIterator
<[number
, V
]>
Returns a new iterator object that contains an array of [key, value]
pairs for each element in the Collection
.
IterableIterator
<[number
, V
]>
An iterable iterator for the entries of the collection.
▸ first(): undefined
| V
Retrieves the first element added to the queue without removing it.
undefined
| V
The first element of the queue, or undefined
if the queue is empty.
▸ forEach(callbackfn
, thisArg?
): void
Executes a provided function once for each key-value pair in the Collection
.
Name | Type | Description |
---|---|---|
callbackfn |
(value : V , key : number , collection : this ) => void |
A function to execute for each element, receiving the value, key, and collection instance as arguments. |
thisArg? |
unknown |
An optional value to use as this when executing callbackfn . |
void
▸ front(): undefined
| V
Retrieves the element at the front of the queue without removing it.
This method provides semantic clarity in contexts where the term "front" is preferred over "first" to describe the element that was added earliest and will be processed next.
undefined
| V
The element at the front of the queue, or undefined
if the queue is empty.
▸ has(value
): boolean
Determines whether a specific element exists within the queue.
Name | Type | Description |
---|---|---|
value |
V |
The value to locate. |
boolean
true
if the value exists, false
otherwise.
▸ keys(): IterableIterator
<number
>
Returns a new iterator that contains the keys for each element
in the Collection
.
IterableIterator
<number
>
An iterable iterator for the keys of the collection.
▸ push(...values
): number
Adds one or more elements to the end of the queue and returns the queue's new length.
Name | Type | Description |
---|---|---|
...values |
V [] |
The elements to add. |
number
The new length of the queue.
▸ shift(): undefined
| V
Removes and returns the first element of the queue.
undefined
| V
The first element of the queue, or undefined
if the queue is empty.
▸ values(): IterableIterator
<V
>
Returns a new iterator that contains the values for each element
in the Collection
.
IterableIterator
<V
>
An iterable iterator for the values of the collection.