lua-users home
lua-l archive

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


On Wed, Sep 18, 2013 at 1:01 AM, Marc Lepage <mlepage@antimeta.com> wrote:
> 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?


Well, I'm not sure if it's faster, since it may have more operations,
but if T1 may be altered, you can do something like:
For every value in T2, check if it exists in T1. If yes, then remove
it from T1, if not, then you know it is new. Then whatever remains in
T1 is what was deleted.

If T1 must remain unchanged, you can create a copy of it and do the
algorithm above, though I suspect the overhead of duplicating the
table will be just the same - if not worse - then loop through both T1
and T2.

---
NI!

() - www.asciiribbon.org
/\ - ascii ribbon campaign against html e-mail and proprietary attachments