lua-users home
lua-l archive

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


On Fri, Mar 30, 2012 at 2:59 PM, Ousmane Roland Yonaba
<roland.yonaba@gmail.com> wrote:
> explaining...You're taking about the speed issue that will certainly
> occur.. Would you mind giving me an example of the reverse lookup you
> were talking about ?

We have a table

T = {dog = 1, cat = 4, lizard = 6}

and the reverse lookup is just:

R = {[1] = 'dog', [4] = 'cat', [6] = 'lizard'}

Some people call this the 'invert' operation:

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

steve d.