lua-users home
lua-l archive

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


Suppose I have two tables T1 and T2.

Each contains entries which have keys like A, B, C and values that are subtables.

The subtables have keys which are like x, y, z and just have value true. (They are sets.)

Something like:

T1 =
{
    A = { x=true, y=true},
    B = { x=true },
}

T2 =
{
    A = { x=true, y=true, z=true },
    C = { x=true },
}

What is the best (most efficient) way of knowing which entries are new to T2 (compared to T1) and which are deleted from T1 (comparing to T2)?

In the case above, we could say:

T1[B][x] was removed
T2[A][z] was added
T2[C][x] was added

I could loop through all of T1 looking for entries not present in T2 (they were removed), and then through all of T2 looking for entries not present in T1 (they were added). But if nothing changed and there were a lot of content, I'd be going through it twice for no real effect.

Better ideas?