Re: How can I deep-compare 2 Lua tables, which may or may not have tables as keys?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: How can I deep-compare 2 Lua tables, which may or may not have tables as keys?
- From: Enrico Colombini <erix@...>
- Date: 2014年9月22日 17:49:52 +0200
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