OpenComputers Von Neumann Machine Programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
608 B

-- Simple FIFO Queue
local Queue = {}
Queue.__index = Queue
setmetatable(Queue, {
__call = function (cls)
return cls.new()
end,
})
function Queue.new()
local self = setmetatable({}, Queue)
self.first = 0
self.last = -1
return self
end
function Queue:push(e)
local last = self.last + 1
self.last = last
self[last] = e
end
function Queue:pop()
-- To save some accesses
local first = self.first
if first > self.last then return nil end
local value = self[first]
self[first] = nil
self.first = first + 1
return value
end
return Queue