Class Queue
Queue for managing values.
The semantics of a queue is to pop the oldest entry pushed into the queue. This class follows the pattern from Lua classes.
Metamethods
Queue:__index (key) | Lookup of missing class members. |
Methods
Queue:create (...) | Create a new instance. |
Queue:_init (...) | Initialize a new instance. |
Queue:isEmpty () | Is the queue empty. |
Queue:depth () | What is the depth of the internal structure. |
Queue:layout () | Get the layout of the queue. |
Queue:bottom () | Get a reference to the bottommost item in the queue. |
Queue:top () | Get a reference to the topmost item in the queue. |
Queue:push (...) | Push a value on the queue. |
Queue:pop ([num=1]) | Pop the last value of the queue. |
Queue:drop ([num=1]) | Drop the last n values of the Queue. |
Queue:get ([num=1]) | Get the indexed entry. |
Queue:export () | Export a list of all the contents. |
Queue:flush () | Flush all the contents. |
Metamethods
- Queue:__index (key)
-
Lookup of missing class members.
Parameters:
- key string lookup of member
Returns:
anyRaises:
on wrong arguments
Methods
- Queue:create (...)
-
Create a new instance.
Parameters:
- ...
vararg
forwarded to
_init()
Returns:
self - ...
vararg
forwarded to
- Queue:_init (...)
-
Initialize a new instance.
Parameters:
- ... vararg pushed on the queue
Returns:
self - Queue:isEmpty ()
-
Is the queue empty.
Note that the internal structure is non-empty even if a nil
is pushed on the queue.
Returns:
boolean whether the internal structure has length zero - Queue:depth ()
-
What is the depth of the internal structure.
Note that the internal structure has a depth even if a nil
is pushed on the queue.
Returns:
number how deep is the internal structure - Queue:layout ()
-
Get the layout of the queue.
This method is used for testing to inspect which types of objects exists in the queue.
Returns:
table description of the queue - Queue:bottom ()
-
Get a reference to the bottommost item in the queue.
The bottommost item can also be described as the first item.
This method leaves the item on the queue.
Nicknames:
-
first
Returns:
any item that can be put on the queue - Queue:top ()
-
Get a reference to the topmost item in the queue.
The topmost item can also be described as the last item.
This method leaves the item on the queue.
Nicknames:
-
last
Returns:
any item that can be put on the queue - Queue:push (...)
-
Push a value on the queue.
Parameters:
- ...
Returns:
self facilitate chaining - Queue:pop ([num=1])
-
Pop the last value of the queue.
Note that this will remove the last (topmost) value.
Parameters:
- num number items to drop (default 1)
Returns:
any item that can be put on the queue - Queue:drop ([num=1])
-
Drop the last n values of the Queue.
Note that this will remove the last (topmost) values.
Parameters:
- num number items to drop (default 1)
Returns:
self facilitate chaining - Queue:get ([num=1])
-
Get the indexed entry.
Accessing this will not change stored values.
Parameters:
- num number entry, negative numbers count backwards (default 1)
Returns:
any item that can be put on the queue - Queue:export ()
-
Export a list of all the contents.
Returns:
table list of values - Queue:flush ()
-
Flush all the contents.
Note that this clears the internal storage.
Returns:
table list of values