BattleDictionary = {} function BattleDictionary.New() local o = {} setmetatable(o, BattleDictionary) BattleDictionary.__index = BattleDictionary o.kList = {} o.vList = {} o.kvList = {} o.size = 0 return o end function BattleDictionary:Add(k,v) if not self.kvList[k] then self.size = self.size + 1 self.kvList[k] = v self.kList[self.size] = k self.vList[self.size] = v end end function BattleDictionary:Remove(k) if self.kvList[k] then for i=1, self.size do if self.vList[i] == self.kvList[k] then self.size = self.size - 1 table.remove(self.kList, i) table.remove(self.vList, i) self.kvList[k] = nil break end end end end function BattleDictionary:Set(k,v) self:Remove(k) self:Add(k,v) end function BattleDictionary:Clear() self.kList = {} self.vList = {} self.kvList = {} self.size = 0 end function BattleDictionary:Count() return self.size end function BattleDictionary:Foreach(func) for i = 1, self.size do if func then func(self.kList[i], self.vList[i]) end end end