--[[ @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
