#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

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

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


#API Documentation

#Functions

Signaturecp.collect.Queue.contains(queue, item) -> boolean
TypeFunction
DescriptionChecks 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 181

Signaturecp.collect.Queue.len(queue) -> anything
TypeFunction
DescriptionReturns the number of items in the queue.
Parameters
  • queue - The queue to check.
Returns
  • The total number of items.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 244

Signaturecp.collect.Queue.peekLeft(queue) -> anything
TypeFunction
DescriptionReturns 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 147

Signaturecp.collect.Queue.peekRight(queue) -> anything
TypeFunction
DescriptionReturns 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 164

Signaturecp.collect.Queue.popLeft(queue) -> anything
TypeFunction
DescriptionRemoves 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 105

Signaturecp.collect.Queue.popRight(queue) -> anything
TypeFunction
DescriptionRemoves 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 126

Signaturecp.collect.Queue.pushLeft(queue, ...) -> cp.collect.Queue
TypeFunction
DescriptionPushes 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 54

Signaturecp.collect.Queue.pushRight(queue, ...) -> cp.collect.Queue
TypeFunction
DescriptionPushes 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 80

Signaturecp.collect.Queue.removeItem(queue, item) -> number
TypeFunction
DescriptionAttempts 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 201

Signaturecp.collect.Queue:removeItem(item) -> number
TypeFunction
DescriptionAttempts 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 347

#Constructors

Signaturecp.collect.Queue.new([...]) -> cp.collect.Queue
TypeConstructor
DescriptionCreates 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 38

#Methods

Signaturecp.collect.Queue:contains(item) -> boolean
TypeMethod
DescriptionChecks if the queue contains the specified item.
Parameters
  • item - The item to check for.
Returns
  • true if the item is in the queue.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 336

Signaturecp.collect.Queue:len(queue) -> anything
TypeMethod
DescriptionReturns the number of items in the queue.
Parameters
  • queue - The queue to check.
Returns
  • The total number of items.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 364

Signaturecp.collect.Queue:peekLeft() -> anything
TypeMethod
DescriptionReturns the left-most value from the queue without removig it.
Parameters
  • None
Returns
  • The left-most value of the Queue.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 314

Signaturecp.collect.Queue:peekRight() -> anything
TypeMethod
DescriptionReturns 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.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 325

Signaturecp.collect.Queue:popLeft() -> anything
TypeMethod
DescriptionRemoves the left-most value from the queue and returns it.
Parameters
  • None
Returns
  • The left-most value of the Queue.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 292

Signaturecp.collect.Queue:popRight() -> anything
TypeMethod
DescriptionRemoves the right-most value from the queue and returns it.
Parameters
  • None
Returns
  • The right-most value of the Queue.
NotesNone
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 303

Signaturecp.collect.Queue:pushLeft(...) -> cp.collect.Queue
TypeMethod
DescriptionPushes 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 260

Signaturecp.collect.Queue:pushRight(...) -> cp.collect.Queue
TypeMethod
DescriptionPushes 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.
ExamplesNone
Sourcesrc/extensions/cp/collect/Queue.lua line 276