Constructor
new ArrayQueue(fifoopt, itemsopt)
Creates an ArrayQueue.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
fifo |
boolean |
<optional> |
true | If true, uses FIFO ordering; otherwise, LIFO. |
items |
Array.<any> |
<optional> |
[] | Optional initial array of items. |
- Source:
Classes
Members
fifo
- Source:
items
- Source:
Methods
add(item) → {boolean}
Appends an item to the queue.
Parameters:
| Name | Type | Description |
|---|---|---|
item |
* | The item to add. |
- Source:
Returns:
Always true.
- Type
- boolean
clear()
Removes all items from the queue.
- Source:
has() → {boolean}
Always returns false because this queue does not support item equivalence.
- Source:
Returns:
- Type
- boolean
n() → {number}
- Source:
Returns:
The number of items in the queue.
- Type
- number
peek(firstopt) → {*}
Retrieves (without removing) the first or last item based on direction.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
first |
boolean |
<optional> |
true | If false, retrieves the last item. |
- Source:
Returns:
The retrieved item.
- Type
- *
poll(firstopt) → {*}
Retrieves and removes the first or last item based on direction.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
first |
boolean |
<optional> |
true | If false, removes from the end. |
- Source:
Returns:
The extracted item.
- Type
- *
remove(item) → {boolean}
Always returns false. Items cannot be removed by value.
Parameters:
| Name | Type | Description |
|---|---|---|
item |
* | The item to remove. |
- Source:
Returns:
Always false.
- Type
- boolean
reverse() → {Each.<any>}
Returns an iterable view over this queue in reverse order.
- Source:
Returns:
An Each instance yielding the queue items from end to start.
- Type
- Each.<any>
select(n, firstopt) → {Array.<*>}
Selects in place the first or last n items, returning the items that were removed.
This overrides Queue.select() with a more performant batch implementation
using Array.splice().
Behavior:
- If
first === true: keep the firstnitems, discard the rest. - If
first === false: keep the lastnitems, discard the rest.
Edge cases:
- If
n >= this.items.length, nothing is discarded. - If
n <= 0, all items are discarded.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
n |
number | Number of items to keep. |
||
first |
boolean |
<optional> |
true | Whether to keep items from the start ( |
- Source:
Returns:
- The discarded items.
- Type
- Array.<*>