The Gundam Wiki
Advertisement
The Gundam Wiki

Documentation for this module may be created at Module:TableTools/doc

local a={}local b=require('libraryUtil')local c=math.floor;local d=math.huge;local e=b.checkType;function a.pack(...)return{n=select('#',...),...}end;function a.selectFirst(f,...)e('Module:TableTools.selectFirst',1,f,'number')local function g()error('bad argument #1 to \'Module:TableTools.selectFirst\' '..'(index out of range)')end;local function h(i,j,...)if i==0 then return end;return j,h(i-1,...)end;f=math.modf(f)local k=select("#",...)if-k>f then g()elseif-1>f and f>=-k then return h(k+1+f,...)elseif f==-1 then return...elseif f==0 then g()elseif f==1 then return...elseif 1<f and f<=k then return h(f,...)elseif k<f then return...end end;function a.isSequence(l)e('Module:TableTools.isSequence',1,l,'table')local m=1;for n in pairs(l)do if l[m]==nil then return false end;m=m+1 end;return true end;function a.size(l)e('Module:TableTools.size',1,l,'table')local m=0;for n in pairs(l)do m=m+1 end;return m end;function a.includes(l,o)e('Module:TableTools.includes',1,l,'table')for n,p in pairs(l)do if p==o then return true end end;return false end;function a.merge(q,r)e('Module:TableTools.merge',1,q,'table')e('Module:TableTools.merge',2,r,'table')for s,p in pairs(r)do if type(p)=='table'and type(q[s])=='table'then a.merge(q[s],p)else q[s]=p end end;return q end;function a.isPositiveInteger(p)if type(p)=='number'and p>=1 and c(p)==p and p<d then return true else return false end end;function a.isNan(p)if type(p)=='number'and tostring(p)=='-nan'then return true else return false end end;function a.shallowClone(l)local t={}for s,p in pairs(l)do t[s]=p end;return t end;function a.removeDuplicates(l)e('removeDuplicates',1,l,'table')local u=a.isNan;local t,v={},{}for m,p in ipairs(l)do if u(p)then t[#t+1]=p else if not v[p]then t[#t+1]=p;v[p]=true end end end;return t end;function a.numKeys(l)e('numKeys',1,l,'table')local w=a.isPositiveInteger;local x={}for s,p in pairs(l)do if w(s)then x[#x+1]=s end end;table.sort(x)return x end;function a.affixNums(l,y,z)e('affixNums',1,l,'table')e('affixNums',2,y,'string',true)e('affixNums',3,z,'string',true)local function A(B)B=B:gsub('([%(%)%%%.%[%]%*%+%-%?%^%$])','%%%1')return B end;y=y or''z=z or''y=A(y)z=A(z)local C='^'..y..'([1-9]%d*)'..z..'$'local x={}for s,p in pairs(l)do if type(s)=='string'then local D=mw.ustring.match(s,C)if D then x[#x+1]=tonumber(D)end end end;table.sort(x)return x end;function a.numData(l,E)e('numData',1,l,'table')e('numData',2,E,'boolean',true)local t={}for s,p in pairs(l)do local y,D=mw.ustring.match(tostring(s),'^([^0-9]*)([1-9][0-9]*)$')if D then D=tonumber(D)local F=t[D]or{}if y==''then y=1 end;F[y]=p;t[D]=F else local F=t.other or{}F[s]=p;t.other=F end end;if E then local G=t.other;t=a.compressSparseArray(t)t.other=G end;return t end;function a.compressSparseArray(l)e('compressSparseArray',1,l,'table')local t={}local x=a.numKeys(l)for n,D in ipairs(x)do t[#t+1]=l[D]end;return t end;function a.sparseIpairs(l)e('sparseIpairs',1,l,'table')local x=a.numKeys(l)local m=0;local H=#x;return function()m=m+1;if m<=H then local I=x[m]return I,l[I]else return nil,nil end end end;return a
Advertisement