--[=[
	@within TableUtil
	@function Copy
	@param tbl table -- Table to copy
	@param deep boolean? -- Whether or not to perform a deep copy
	@return table

	Creates a copy of the given table. By default, a shallow copy is
	performed. For deep copies, a second boolean argument must be
	passed to the function.

	:::caution No cyclical references
	Deep copies are _not_ protected against cyclical references. Passing
	a table with cyclical references _and_ the `deep` parameter set to
	`true` will result in a stack-overflow.
]=]

local function Copy(t: Table, deep: boolean?): Table
	if deep then
		local function DeepCopy(tbl)
			local tCopy = table.create(#tbl)
			for k,v in pairs(tbl) do
				if type(v) == "table" then
					tCopy[k] = DeepCopy(v)
				else
					tCopy[k] = v
				end
			end
			return tCopy
		end
		return DeepCopy(t)
	else
		if #t > 0 then
			return table.move(t, 1, #t, 1, table.create(#t))
		else
			local tCopy = {}
			for k,v in pairs(t) do
				tCopy[k] = v
			end
			return tCopy
		end
	end
end

