dreamworkAPI
Ctrl K
GitHub
classDocs / Queue

Queue

classsharedmenusource
Object → Queue

A queue is a first-in-first-out (FIFO) data structure object.

Values are appended at one end and removed from the other by default (push appends to the front, pop removes from the back), so the earliest-pushed value is the first one popped.

Both push and pop accept an optional flag to operate on the opposite end instead, which lets the same object also be used as a deque.

Elements are stored between the back and front indices, which are advanced/rewound as values are pushed and popped, and are reset to 0 whenever the queue becomes empty.

Constructor

Queue(): Queue

Fields

NameTypeDescription
frontintegerThe front of the queue. Read-only
backintegerThe back of the queue. Read-only

Methods

clearEmpties the queue, removing every value and resetting front and back to 0.
isEmptyChecks if the queue is empty.
iteratorReturns an iterator for the queue.
peekReturns the value at the front of the queue or the back if from_tail is true.
popRemoves and returns the value at the back of the queue or the front if from_tail is true.
pushAppends a value to the end of the queue or the front if to_head is true.

#Queue:clear

sharedmenusource
function Queue:clear()

Empties the queue, removing every value and resetting front and back to 0.

#Queue:isEmpty

sharedmenunodiscardsource
function Queue:isEmpty(): boolean

Checks if the queue is empty.

Returns
TypeNameDescription
booleanis_emptyReturns true if the queue has no values, otherwise false.

#Queue:iterator

sharedmenunodiscardsource
function Queue:iterator(from_tail?: boolean): (fun( queue: Queue<T>, from_tail: boolean ): T), Queue<T>, boolean

Returns an iterator for the queue.

Parameters
NameTypeDescription
from_tailoptionalbooleanIf true, returns an iterator for the back of the queue.
Returns
TypeNameDescription
fun( queue: Queue<T>, from_tail: boolean ): TiteratorThe iterator function.
Queue<T>queueThe queue being iterated over.
booleanfrom_tailtrue if the iterator is for the back of the queue.

#Queue:peek

sharedmenunodiscardsource
function Queue:peek(from_tail?: boolean): T | nil

Returns the value at the front of the queue or the back if from_tail is true.

Parameters
NameTypeDescription
from_tailoptionalbooleanIf true, returns the value at the back of the queue.
Returns
TypeNameDescription
T | nilvalueThe value at the front of the queue, or nil if the queue is empty.

#Queue:pop

sharedmenusource
function Queue:pop(from_tail?: boolean): T | nil

Removes and returns the value at the back of the queue or the front if from_tail is true.

Parameters
NameTypeDescription
from_tailoptionalbooleanIf true, removes and returns the value at the front of the queue.
Returns
TypeNameDescription
T | nilvalueThe value at the back of the queue or the front if from_tail is true, or nil if the queue is empty.

#Queue:push

sharedmenusource
function Queue:push(value: T, to_head?: boolean)

Appends a value to the end of the queue or the front if to_head is true.

Parameters
NameTypeDescription
valueTThe value to append.
to_headoptionalbooleanIf true, appends the value to the front of the queue.
Generated from the dreamwork meta branch.