newTable.vsort=function(E,A)A=A or function(E,A)return E>A end return newTable.xsort(E,function(m,Y)return A(E[m],E[Y])end)end newTable.choice=function(E,A)A=A or 1 local m={}local Y={}for E,A in pairs(E)do Y[E]=A end local h=newTable.keys(Y)for A=1,math.min(#E,math.max(A,1)),1 do table.insert(m,E[table.remove(h,math.random(#h))])end return unpack(m)end newTable.one=function(E)return E[math.random(#E)]end newTable.shallow=function(E)local A={}for E,m in pairs(E)do A[E]=m end return A end newTable.deep=function(E)local A={}for E,m in pairs(E)do if typeof(m)=="\116\097\098\108\101"then A[E]=newTable.deep(m)else A[E]=m end end return A end newTable.cloneKeys=function(E)local A={}for E,m in pairs(E)do A[E]=true end return A end newTable.dump=function(E,A)A=A or""for E,m in pairs(E)do print(("\037\115\037\115 \061 \037\115"):format(A,tostring(E),tostring(m)))if typeof(m)=="\116\097\098\108\101"then newTable.dump(m,("\037\115\046\037\115"):format(A,E))end end end newTable.merge=function(E,...)local A={}for E,m in pairs({E,...})do for E,m in pairs(m)do table.insert(A,m)end end return A end return setmetatable(newTable,{__index=table})

newTable.vsort = function(tbl, sort)
	sort = sort or function(x, y)
		return x > y
	end
	
	return newTable.xsort(tbl, function(x, y)
		return sort(tbl[x], tbl[y])
	end)
end

newTable.choice = function(tbl, resultCount)
	resultCount = resultCount or 1
	
	local results = {}
	
	--clone the table
	local clone = {}
	
	for i,v in pairs(tbl) do
		clone[i] = v
	end
	
	local keys = newTable.keys(clone)
	
	for i=1,math.min(#tbl, math.max(resultCount, 1)) do
		table.insert(results, tbl[table.remove(keys, math.random(#keys))])
	end
	
	return unpack(results)
end

newTable.one = function(tbl)
	return tbl[math.random(#tbl)]
end

newTable.shallow = function(tbl)
	local clone = {}
	
	for key,val in pairs(tbl) do
		clone[key] = val
	end
	
	return clone
end

newTable.deep = function(tbl)
	local clone = {}
	
	for key,val in pairs(tbl) do
		if typeof(val) == "table" then
			clone[key] = newTable.deep(val)
		else
			clone[key] = val
		end
	end
	
	return clone
end

newTable.cloneKeys = function(tbl)
	local ret = {}
	
	for key,_ in pairs(tbl) do
		ret[key] = true
	end
	
	return ret
end

newTable.dump = function(tbl, prefix)
	prefix = prefix or ""
	
	for key,val in pairs(tbl) do
		print(("%s%s = %s"):format(prefix, tostring(key), tostring(val)))
		
		if typeof(val) == "table" then
			newTable.dump(val, ("%s.%s"):format(prefix, key))
		end
	end
end

newTable.merge = function(tbl, ...)
	local ret = {}
	
	for _,tbl in pairs({tbl, ...}) do
		for _,value in pairs(tbl) do
			table.insert(ret, value)
		end
	end
	
	return ret
end

return setmetatable(newTable, {
	__index = table
})
