lua-users home
lua-l archive

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


On 20 September 2014 09:05, Thiago L. <fakedme@gmail.com> wrote:
> Also posted on http://stackoverflow.com/q/25922437/3691554
>
> So I've been writing deep-copy algorithms, and I wanna test them to see if
> they work the way I want them to. While I do have access to the
> original->copy map, I want a general-purpose deep-compare algorithm that
> must be able to compare table keys (tables as keys?). The #Lua channel on
> Freenode thinks it's impossible, I just think it's really hard.

As others said, that depends a lot on your definition of equivalence.
Let's take Paul's example from StackOverflow. Do you want this to
return true?

local t1 = {[{}] = {1}, [{}] = {2}}
local t2 = {[{}] = {1}, [{}] = {2}}
equiv(t1, t2)

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.

-- Hisham