--[[ @brief Packs a table so that no gaps exist.
     @param t The table to pack.
     @param maxn The highest index (obtained by table.maxn if nil).
--]]

function module.CloseGaps(t, maxn)
	if not maxn then maxn = table.maxn(t); end
	local j = 1;
	for i = 1, maxn do
		if t[i] ~= nil then
			if i > j then
				t[j] = t[i];
				t[i] = nil;
			end
			j = j + 1;
		end
	end
end
