jsdiff icon indicating copy to clipboard operation
jsdiff copied to clipboard

How to minimize the number of insertions?

Open nachocab opened this issue 8 years ago • 2 comments

image

The example above showcases what I'm trying to do: the first line has two insertions ("very", "correct and"), while the second line only has one insertion ("and correct"). Is there a parameter I could use to penalize gap opening? That way, the first example would have a single insertion "very and correct"

nachocab avatar Feb 15 '17 13:02 nachocab

No such option currently; we don't have any concept of customising edit costs / penalties. Implementing anything along these lines would probably be a pretty major algorithm change, I think (except maybe something that uses this as a way to tiebreak between routes of equal edit distance - but I'm not totally sure that even that is straightforward!).

ExplodingCabbage avatar Dec 22 '23 16:12 ExplodingCabbage

I'll have a think about this, and will read up on diffing algorithms that allow custom gap penalties (like Smith-Waterman and Needleman-Wunsch) but if I ultimately conclude that this would require a fundamentally different algorithm to the Myers diff algorithm that jsdiff currently uses, I'll probably close this.

ExplodingCabbage avatar Dec 22 '23 17:12 ExplodingCabbage