# cp.collect.Queue

A "double-ended queue" implementation. This allows pushing and popping values to the left or right side of the queue. This can be used for classic 'stack' and 'queue' uses - for a stack, push and pop from one end, for a queue, push and pop from opposite ends.

# will always return the size of the queue.

The left-most item in the queue wil always be at index 1, the right-most will be at index #.

You can iterate via ipairs, but as with all tables, the queue contains any nil values, it will stop at that point. To iterate the whole queue, you need to use the # operator. Eg:

local q = Queue(1, nil, 3)
for i,v in ipairs(q) do print(v) end  -- Outputs "1"
for i = 1, #q do print(v) end -- Outputs "1", "nil", "3"

# API Overview

Functions - API calls offered directly by the extension

  • contains
  • len
  • peekLeft
  • peekRight
  • popLeft
  • popRight
  • pushLeft
  • pushRight
  • removeItem
  • removeItem

Constructors - API calls which return an object, typically one that offers API methods

  • new

Methods - API calls which can only be made on an object returned by a constructor

  • contains
  • len
  • peekLeft
  • peekRight
  • popLeft
  • popRight
  • pushLeft
  • pushRight

# API Documentation

# Functions

# contains

Signature cp.collect.Queue.contains(queue, item) -> boolean
Type Function
Description Checks if the queue contains the specified item.
Parameters
  • queue - The queue to check.
  • item - The item to check for.
Returns
  • true if the item is in the queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 181

# len

Signature cp.collect.Queue.len(queue) -> anything
Type Function
Description Returns the number of items in the queue.
Parameters
  • queue - The queue to check.
Returns
  • The total number of items.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 244

# peekLeft

Signature cp.collect.Queue.peekLeft(queue) -> anything
Type Function
Description Returns the left-most value from the queue without removig it.
Parameters
  • queue - The queue to peek into.
Returns
  • The left-most value of the Queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 147

# peekRight

Signature cp.collect.Queue.peekRight(queue) -> anything
Type Function
Description Returns the right-most value from the queue without removig it.
Parameters
  • queue - The queue to peek into.
Returns
  • The right-most value of the Queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 164

# popLeft

Signature cp.collect.Queue.popLeft(queue) -> anything
Type Function
Description Removes the left-most value from the queue and returns it.
Parameters
  • queue - The queue to pop from.
Returns
  • The left-most value of the Queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 105

# popRight

Signature cp.collect.Queue.popRight(queue) -> anything
Type Function
Description Removes the right-most value from the queue and returns it.
Parameters
  • queue - The queue to pop from.
Returns
  • The right-most value of the Queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 126

# pushLeft

Signature cp.collect.Queue.pushLeft(queue, ...) -> cp.collect.Queue
Type Function
Description Pushes the values to the left side of the queue.
Parameters
  • queue - The queue to push into.
  • ... - The values to push.
Returns
  • The same Queue instance.
Notes
  • If there are multiple values, then they will be added from right to left.
  • That is to say, the left-most of the new values will be the left-most value of the queue.
Examples None
Source src/extensions/cp/collect/Queue.lua line 54

# pushRight

Signature cp.collect.Queue.pushRight(queue, ...) -> cp.collect.Queue
Type Function
Description Pushes the values to the right side of the queue.
Parameters
  • queue - The queue to push into.
  • ... - The values to push.
Returns
  • The same Queue instance.
Notes
  • If there are multiple values, then they will be added from left to right.
  • That is to say, the right-most of the new values will be the right-most value of the queue.
Examples None
Source src/extensions/cp/collect/Queue.lua line 80

# removeItem

Signature cp.collect.Queue.removeItem(queue, item) -> number
Type Function
Description Attempts to remove the specified item from the queue.
Parameters
  • queue - The queue to modify.
  • item - The item to remove, if present.
Returns
  • The index of the item, or nil if not found.
Notes
  • This call may be very expensive if there are many items in the queue after the specified item.
  • If the item was found, the index it was found at is returned.
  • If not, nil is returned.
Examples None
Source src/extensions/cp/collect/Queue.lua line 201

# removeItem

Signature cp.collect.Queue:removeItem(item) -> number
Type Function
Description Attempts to remove the specified item from the queue.
Parameters
  • item - The item to remove, if present.
Returns
  • The index of the item, or nil if not found.
Notes
  • This call may be very expensive if there are many items in the queue after the specified item.
  • If the item was found, the index it was found at is returned.
  • If not, nil is returned.
Examples None
Source src/extensions/cp/collect/Queue.lua line 347

# Constructors

# new

Signature cp.collect.Queue.new([...]) -> cp.collect.Queue
Type Constructor
Description Creates a new Queue.
Parameters
  • ... - The optional list of values to add to the right of the queue.
Returns
  • the new Queue.
Notes
  • You can also create a new queue by calling Queue(..) directly.
Examples None
Source src/extensions/cp/collect/Queue.lua line 38

# Methods

# contains

Signature cp.collect.Queue:contains(item) -> boolean
Type Method
Description Checks if the queue contains the specified item.
Parameters
  • item - The item to check for.
Returns
  • true if the item is in the queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 336

# len

Signature cp.collect.Queue:len(queue) -> anything
Type Method
Description Returns the number of items in the queue.
Parameters
  • queue - The queue to check.
Returns
  • The total number of items.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 364

# peekLeft

Signature cp.collect.Queue:peekLeft() -> anything
Type Method
Description Returns the left-most value from the queue without removig it.
Parameters
  • None
Returns
  • The left-most value of the Queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 314

# peekRight

Signature cp.collect.Queue:peekRight() -> anything
Type Method
Description Returns the right-most value from the queue without removig it.
Parameters
  • queue - The queue to peek into.
Returns
  • The right-most value of the Queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 325

# popLeft

Signature cp.collect.Queue:popLeft() -> anything
Type Method
Description Removes the left-most value from the queue and returns it.
Parameters
  • None
Returns
  • The left-most value of the Queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 292

# popRight

Signature cp.collect.Queue:popRight() -> anything
Type Method
Description Removes the right-most value from the queue and returns it.
Parameters
  • None
Returns
  • The right-most value of the Queue.
Notes None
Examples None
Source src/extensions/cp/collect/Queue.lua line 303

# pushLeft

Signature cp.collect.Queue:pushLeft(...) -> cp.collect.Queue
Type Method
Description Pushes the values to the left side of the queue.
Parameters
  • ... - The values to push.
Returns
  • The same Queue instance.
Notes
  • If there are multiple values, then they will be added from right to left.
  • That is to say, the left-most of the new values will be the left-most value of the queue.
Examples None
Source src/extensions/cp/collect/Queue.lua line 260

# pushRight

Signature cp.collect.Queue:pushRight(...) -> cp.collect.Queue
Type Method
Description Pushes the values to the right side of the queue.
Parameters
  • ... - The values to push.
Returns
  • The same Queue instance.
Notes
  • If there are multiple values, then they will be added from left to right.
  • That is to say, the right-most of the new values will be the right-most value of the queue.
Examples None
Source src/extensions/cp/collect/Queue.lua line 276