Sujet : Re: using struct::list::longestCommonSubsequence for diff/patch
De : ralfixx (at) *nospam* gmx.de (Ralf Fassel)
Groupes : comp.lang.tclDate : 18. Jul 2025, 13:58:14
Autres entêtes
Message-ID : <ygaseity7tl.fsf@akutech.de>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
* Mark Summerfield <
m.n.summerfield@gmail.com>
| 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'