• Re: using struct::list::longestCommonSubsequence for diff/patch

    From Ralf Fassel@21:1/5 to All on Fri Jul 18 14:58:14 2025
    * Mark Summerfield <[email protected]>
    | Below is the code I'm using. There are two examples, both of which diff two
    | lists to produce a "patch edits" list, and then take the first list and the
    | patch edits in an attempt to reconstruct the second list. The first succeeds | and the second fails.

    | Clearly I'm doing something wrong. I feel confident that `edits` is correct
    | since it really just uses the data from
    | `struct::list::longestCommonSubsequence`; so I'm pretty sure my bug(s) is(are)
    | in `patch`.

    Since you are replacing 'lines' in [patch] in the edit-loop, the indices
    are wrong once the number of elements change due to an insertion or
    deletion. In your first example, you only ever insert/delete single
    elements (or equal-size chunks), but in the second example, the number
    of elements are different between old and new.

    I think you need to build the new list piecewise somehow or at least
    keep a copy of the original lines in order to apply the indices to it.

    Also I'm not sure whether it is ok to enter an operation more than once
    in [edit]. I.e.

    changed {1 2} {1 1}
    becomes
    {- 1 2} {- 1 2} {+ 1 2 beta}

    due to the 'foreach' iterating over {1 2}.

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)