Module lib.container.deque
Create a Deque value (object).
A double ended queue supporting O(1) insertion at the head or tail of the queue.
Functions
Deque:push (value) | Push a value onto the front of the queue |
Deque:push_back (value) | Push a value onto the back of the queue |
Deque:extend_back (other_deque) | Push all values from another Deque onto theback of this one |
Deque:pop () | Pop the value off the front of the queue and return it |
Deque:pop_back () | Pop the value off the back of the queue and return it |
Deque:find (value, predicate) | Returns the queued value if the a match is found. |
Deque:contains (value, predicate) | Returns true if the given value is in the queue. |
Deque:remove (value, predicate) | Removes the first instance over value in the queue
The optional predicate function should take two arguments and return true if the arguments are considered a match. |
Deque:count () | Return the number of elements/values in the queue |
Deque:clear () | Clear out all elements in the queue |
Deque:ipairs () | Returns an iterator for the queue which behaves like ipairs |
Deque:to_array () | Return a list/array with the elements of the queue (here head is index 1) |
Functions
- Deque:push (value)
-
Push a value onto the front of the queue
Parameters:
- value anything The value to insert
- Deque:push_back (value)
-
Push a value onto the back of the queue
Parameters:
- value anything The value to insert
- Deque:extend_back (other_deque)
-
Push all values from another Deque onto theback of this one
Parameters:
- other_deque Deque The values to insert
- Deque:pop ()
-
Pop the value off the front of the queue and return it
Returns:
-
anything
- Deque:pop_back ()
-
Pop the value off the back of the queue and return it
Returns:
-
anything
- Deque:find (value, predicate)
-
Returns the queued value if the a match is found.
The optional predicate function should take two arguments and return true if the arguments are considered a match. The default predicate is ==.
Parameters:
- value anything The value to search the queue for
- predicate function Comparison function [optional]
Returns:
-
anything
- Deque:contains (value, predicate)
-
Returns true if the given value is in the queue.
The optional predicate function should take two arguments and return true if the arguments are considered a match. The default predicate is ==.
Parameters:
- value anything The value to search the queue for
- predicate function Comparison function [optional]
Returns:
-
boolean
- Deque:remove (value, predicate)
-
Removes the first instance over value in the queue
The optional predicate function should take two arguments and return true if the arguments are considered a match. The default predicate is ==.
Parameters:
- value anything The value to remove from the queue
- predicate function Comparison function [optional]
Returns:
-
anything
Removed value or nil
- Deque:count ()
-
Return the number of elements/values in the queue
Returns:
-
int
- Deque:clear ()
- Clear out all elements in the queue
- Deque:ipairs ()
-
Returns an iterator for the queue which behaves like ipairs
Returns:
-
function
- Deque:to_array ()
- Return a list/array with the elements of the queue (here head is index 1)