function Signal:add_set_up(set_up_func)
if (type(set_up_func) ~= "function") then
error("add_set_up: expected function...")
end
if not self.set_up_funcs[set_up_func] then
self.set_up_funcs[#self.set_up_funcs+1] = set_up_func
self.set_up_funcs[set_up_func] = #self.set_up_funcs
end
end
function Signal:remove_set_up(set_up_func)
local pos = self.set_up_funcs[set_up_func]
if pos then
table.remove(self.set_up_funcs, pos)
self.set_up_funcs[set_up_func] = nil
end
end
The con is that we will have a larger table.
The pro is faster lookup ( O(1) instead of O(n) ) of the position of the function (used to check if a function is already inserted and to remove it).
Something like this:
The con is that we will have a larger table. The pro is faster lookup ( O(1) instead of O(n) ) of the position of the function (used to check if a function is already inserted and to remove it).