slagel has asked for the wisdom of the Perl Monks concerning the following question:

Hellooo Monks, I have a question regarding maintaining a delta log of a large unordered list. I'm going to be storing a list of 50-100,000 items in a database and would like to keep track of all changes (additions/deletions) of said list, kinda like a revision log.

Can anyone suggest a good data structure to use for this? I've considered the both "brute" force methods, either just keeping (n) copies of the list or keeping one list and a list of changes but there seems like there should be a better way. Thanks!

Replies are listed 'Best First'.
Re: Maintaining deltas of a long list
by johnnywang (Priest) on Aug 12, 2004 at 23:58 UTC
    I have a similar case where I'm storing my data in a database, in this case I use database triggers to capture insert/delete/update events, and log them in a separate table, sort of like a transaction log. In this way, I have one table containing the current data, and another containing the (time ordered) change log.

    You can also do the same if you are storing your data in a file. It's easy to find the difference between two lists (see the Cookbook's Array chapter), and write the diff in another file (or even the same file) with, say, +/- indicator.

      Algorithm::Diff determines diffs between two files and its sdiff method lets you even display before-and-after versions side-by-side.
        This is right in line with what I was looking for. Thanks!
Re: Maintaining deltas of a long list
by Plankton (Vicar) on Aug 12, 2004 at 23:16 UTC
    If these list are stored in a file maybe you could use something like CVS to track the changes.

    Plankton: 1% Evil, 99% Hot Gas.