1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/utils/Queue.lua
Matthew c49f5007fa Utils cleanup (#411)
* Clean up unused vars and using same var names

* Autoformat
2018-11-20 11:46:42 +01:00

34 lines
539 B
Lua

local Queue = {}
function Queue.new()
local queue = {_head = 0, _tail = 0}
return queue
end
function Queue.size(queue)
return queue._tail - queue._head
end
function Queue.push(queue, element)
local index = queue._head
queue[index] = element
queue._head = index - 1
end
function Queue.peek(queue)
return queue[queue._tail]
end
function Queue.pop(queue)
local index = queue._tail
local element = queue[index]
queue[index] = nil
queue._tail = index - 1
return element
end
return Queue