lua-users home
lua-l archive

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


On 22/09/2014 16.08, Hisham wrote:
If you do, then each time the key in t1 is a table, you'll have to
check its equivalence with every table key in t2 and try them one by
one.

To remove an O(n^2) worst case in my ebook compiler [1] I encountered a similar problem: I needed to access a table tt using the contents of a table tk as key, so I serialized tk with its keys ordered and used the resulting string as key for tt.

It is neither very fast nor memory-efficient because I have to serialize a table before using it as a key, but retrieving a value from tt (keyed by table contents) only requires a single access.

[1] http://www.erix.it/medusa.html
(look for VtableToString in medusa.lua)

--
  Enrico