This Lua module provides the data structure for a queue. A queue structure works like a line to get into the movies. It works in a first in, first out way. First element added to the queue gets out first.
You can use the module by putting the repo into your project, and require it with:
queue = require "tablua.queue"
Creates a new instance of the Queue class.
If table:'t' is passed, that will be the initial table that is used.
Checks if the table:a
is an ordered array.
Returns: true if a
is an array, false otherwise.
Add an object into the queue.
any: value
The object to add.
Remove an object from the queue and returns it.
Returns the first object in line, but doesn't remove it.
Clears the queue. This retains the same address as the original.
If you don't care about retaining the same address, then create a new queue.
local queue = queue.new{1,2,3,4,5}
queue:clear() -- same table is now empty
local queue = queue.new{1,2,3,4,5}
queue = queue.new{} -- faster, but a new table
Returns true if any:value
is found inside the queue, otherwise false.
Returns an iterator of the queue.
Copies the queue and returns a new cloned queue.
Works like Lua's table.concat.