lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> table.invert = function (t)
> 	local i = {}
> 	for k in pairs(t) do
> 		i[t[k]] = true
> 	end
> 	return i
> end

A faster version that avoids double indexing:

  table.invert = function (t)
  	local i = {}
  	for k,v in pairs(t) do
  		i[v] = true
  	end
  	return i
  end