mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 20:33:54 -04:00
Initial commit
This commit is contained in:
commit
58549d6b0a
14 changed files with 665 additions and 0 deletions
53
fluid/list.lua
Normal file
53
fluid/list.lua
Normal file
|
@ -0,0 +1,53 @@
|
|||
local List = {}
|
||||
local mt = {__index = List}
|
||||
|
||||
function List.new()
|
||||
return setmetatable({
|
||||
numerical = {},
|
||||
named = {},
|
||||
size = 0,
|
||||
}, mt)
|
||||
end
|
||||
|
||||
function List:clear()
|
||||
self.numerical = {}
|
||||
self.named = {}
|
||||
self.size = 0
|
||||
end
|
||||
|
||||
function List:add(obj)
|
||||
local size = self.size + 1
|
||||
|
||||
self.numerical[size] = obj
|
||||
self.named[obj] = size
|
||||
self.size = size
|
||||
end
|
||||
|
||||
function List:remove(obj)
|
||||
local index = self.named[obj]
|
||||
local size = self.size
|
||||
|
||||
if index == size then
|
||||
self.numerical[size] = nil
|
||||
else
|
||||
local other = self.numerical[size]
|
||||
|
||||
self.numerical[index] = other
|
||||
self.named[other] = index
|
||||
end
|
||||
|
||||
self.named[obj] = nil
|
||||
self.size = size - 1
|
||||
end
|
||||
|
||||
function List:get(i)
|
||||
return self.numerical[i]
|
||||
end
|
||||
|
||||
function List:getIndex(obj)
|
||||
return self.named[obj]
|
||||
end
|
||||
|
||||
return setmetatable(List, {
|
||||
__call = function() return List.new() end,
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue