dcsext.containers.Queue

Queue - doubly ended queue with head and tail access.

Contents

  1. Description
  2. Metamethods
    1. queue:__call()
  3. Methods
    1. queue:pushhead(v)
    2. queue:pophead()
    3. queue:pushtail(v)
    4. queue:poptail()
    5. queue:peekhead()
    6. queue:peektail()
    7. queue:size()
    8. queue:empty()
    9. queue:iterate()
    10. queue:riterate()

Description

Values are stored in a flat table indexed by position, giving constant time push, pop and peek operations at both ends. Create a queue by calling the class directly, e.g. local q = Queue().

Metamethods

queue:__call()

Constructor. Create a new, empty queue by calling the class directly, e.g. local q = Queue().

Returns

  • a new, empty Queue instance

Methods

queue:pushhead(v)

Push a value onto the head of the queue.

Parameters

v
value to store, nil values are ignored

queue:pophead()

Pop the value at the head off the queue.

Returns

  • the value previously at the head or nil when the queue is empty

queue:pushtail(v)

Push a value onto the tail of the queue.

Parameters

v
value to store, nil values are ignored

queue:poptail()

Pop the value at the tail off the queue.

Returns

  • the value previously at the tail or nil when the queue is empty

queue:peekhead()

Return the value at the head without removing it.

Returns

  • the value at the head or nil when the queue is empty

queue:peektail()

Return the value at the tail without removing it.

Returns

  • the value at the tail or nil when the queue is empty

queue:size()

Return the number of values stored in the queue.

Returns

  • the number of stored values

queue:empty()

Test if the queue holds no values.

Returns

  • bool, true when the queue is empty

queue:iterate()

Iterate over the values in the queue from head to tail.

Returns

  • an iterator function for use in a for-in loop, yielding the index and value of each entry; iterating an empty queue yields nothing

queue:riterate()

Iterate over the values in the queue from tail to head.

Returns

  • an iterator function for use in a for-in loop, yielding the index and value of each entry in reverse order; iterating an empty queue yields nothing