function module.Incorporate(g,p)for p,J in pairs(p)do if g[p]==nil then g[p]=J end end return g end function module.StableSort(g,p)for J=1,#g,1 do local I=1 while I<J and not p(g[J],g[I])do I=I+1 end for p=J-1,I,-1 do g[p],g[p+1]=g[p+1],g[p]end end end function module.ConvertArrayToMap(g)local p={}for J=1,#g,1 do p[g[J]]=true end return p end return module
--[[ @brief Pulls all key-value pairs from 'draw' so long as they don't already exist in 'origin'.
     @param origin The table to modify (this is in-place).
     @param draw The table to pull into 'origin'.
     @return A reference to 'origin'. It will have all keys defined which are defined in origin or draw.
--]]
function module.Incorporate(origin, draw)
	for i, v in pairs(draw) do
		if origin[i] == nil then
			origin[i] = v
		end
	end
	return origin
end

function module.StableSort(t, compare)
	for i = 1, #t do
		local j = 1
		while j < i and not compare(t[i], t[j]) do
			j = j + 1
		end
		for k = i - 1, j, -1 do
			t[k], t[k + 1] = t[k + 1], t[k]
		end
	end
end

function module.ConvertArrayToMap(t)
	local s = {}
	for i = 1, #t do
		s[t[i]] = true
	end
	return s
end

return module
