Skip to content

Data Queue

scripts/vscripts/alyxlib/data/queue.lua

Methods

Enqueue

Adds values to the queue in the order they are provided.

Queue:Enqueue(...)

Parameters

  • ...

Dequeue

Removes and returns one or more items from the front of the queue.

If count is omitted, a single item will is dequeued.

Queue:Dequeue(count)

Parameters

  • count (optional)
    number
    Number of items to dequeue

Returns - ... The dequeued items in the original insertion order

Front

Peeks at a number of items at the front of the queue without removing them.

Queue:Front(count)

Parameters

  • count (optional)
    number
    Number of items to peek at

Returns - ... The peeked items

Back

Peeks at a number of items at the back of the queue without removing them.

Queue:Back(count)

Parameters

  • count (optional)
    number
    Number of items to peek at

Returns - ... The peeked items

Remove

Removes a value from the queue regardless of its position.

Queue:Remove(value)

Parameters

  • value
    any
    The value to remove

MoveToBack

Moves an existing value to the back of the queue.

Only the furthest back occurance will be moved.

Queue:MoveToBack(value)

Parameters

  • value
    any
    The value to move

Returns - boolean True if value was found and moved

MoveToFront

Moves an existing value to the front of the queue.

Only the furthest back occurance will be moved.

Queue:MoveToFront(value)

Parameters

  • value
    any
    The value to move

Returns - boolean True if value was found and moved

Contains

Gets if this queue contains a value.

Queue:Contains(value)

Parameters

  • value
    any
    The value to search for

Returns - boolean True if the value is in the queue

Length

Returns the number of items in the queue.

Queue:Length()

Returns - integer The number of items

IsEmpty

Gets if the stack is empty.

Queue:IsEmpty()

Returns - boolean True if the stack is empty

pairs

Helper method for looping.

Queue:pairs()

Returns

  • function

  • any[]

  • number
    i

Functions

Queue

Create a new Queue instance.

Last value is at the front of the queue.

E.g.

Example
local queue = Queue(
    "Back",
    "Middle",
    "Front"
)
Queue(...)

Parameters

  • ...

Returns - Queue The new queue

Types

Queue

Queue data structure.