newTable.vsort=function(h,b)b=b or function(h,b)return h>b end return newTable.xsort(h,function(I,r)return b(h[I],h[r])end)end newTable.choice=function(h,b)b=b or 1 local I={}local r={}for h,b in pairs(h)do r[h]=b end local Q=newTable.keys(r)for b=1,math.min(#h,math.max(b,1)),1 do table.insert(I,h[table.remove(Q,math.random(#Q))])end return unpack(I)end newTable.one=function(h)return h[math.random(#h)]end newTable.shallow=function(h)local b={}for h,I in pairs(h)do b[h]=I end return b end newTable.deep=function(h)local b={}for h,I in pairs(h)do if typeof(I)=="\116\097\098\108\101"then b[h]=newTable.deep(I)else b[h]=I end end return b end newTable.cloneKeys=function(h)local b={}for h,I in pairs(h)do b[h]=true end return b end newTable.dump=function(h,b)b=b or""for h,I in pairs(h)do print(("\037\115\037\115 \061 \037\115"):format(b,tostring(h),tostring(I)))if typeof(I)=="\116\097\098\108\101"then newTable.dump(I,("\037\115\046\037\115"):format(b,h))end end end newTable.merge=function(h,...)local b={}for h,I in pairs({h;...})do for h,I in pairs(I)do table.insert(b,I)end end return b end return setmetatable(newTable,{__index=table})
--sort by values
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,
})
