-- Penlight 1.11.0-1 | /lua/pl/OrderedMap.lua | https://github.com/lunarmodules/Penlight | License: MIT | Minified using https://www.npmjs.com/package/luamin/v/1.0.4
-- Copyright (C) 2009-2016 Steve Donovan, David Manura.
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local a=require'pl.tablex'local b=require'pl.utils'local c=require'pl.List'local d,e,f=a.index_by,table.sort,table.concat;local g=require'pl.class'local h=require'pl.Map'local i=g(h)i._name='OrderedMap'local rawset=rawset;function i:_init(j)rawset(self,'_keys',c())if j then local k,l=self:update(j)if not k then error(l,2)end end end;local m,n=b.assert_arg,b.raise;function i:update(j)m(1,j,'table')if i:class_of(j)then for o,p in j:iter()do self:set(o,p)end elseif#j>0 then if type(j[1])=='table'then for q,r in ipairs(j)do local s,t=next(r)if not s then return n'empty pair initialization table'end;self:set(s,t)end else return n'cannot use an array to initialize an OrderedMap'end else for o,p in pairs(j)do self:set(o,p)end end;return self end;function i:set(s,u)if rawget(self,s)==nil and u~=nil then self._keys:append(s)rawset(self,s,u)else if u==nil then self._keys:remove_value(s)rawset(self,s,nil)else self[s]=u end end;return self end;i.__newindex=i.set;function i:insert(v,s,u)local w=self[s]u=u or w;if w then self._keys:remove_value(s)end;if u then self._keys:insert(v,s)rawset(self,s,u)end;return self end;function i:keys()return self._keys end;function i:values()return c(d(self,self._keys))end;function i:sort(x)e(self._keys,x)return self end;function i:iter()local y=0;local z=self._keys;local A;return function()y=y+1;if y>#z then return nil end;A=z[y]return A,self[A]end end;i.__pairs=i.iter;function i:__tostring()local B={}for y,p in ipairs(self._keys)do local u=self[p]local C=tostring(u)if type(u)~='number'then C='"'..C..'"'end;B[y]=tostring(p)..'='..C end;return'{'..f(B,',')..'}'end;return i
