diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2021-03-21 13:34:01 -0700 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2021-03-21 13:34:01 -0700 |
commit | ccd6ac4d44b5c91aa2d1c2534c7be57963b616d5 (patch) | |
tree | 3bf4b157dc8bf91e7d97e206c4bb5e8272a17a5d /text_diff_notes.md | |
parent | 5b182575981af686459ab9f72310719d9c2cfff4 (diff) |
Add notes on LCS weaknesses
Diffstat (limited to 'text_diff_notes.md')
-rw-r--r-- | text_diff_notes.md | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/text_diff_notes.md b/text_diff_notes.md new file mode 100644 index 000000000..c4a183dea --- /dev/null +++ b/text_diff_notes.md @@ -0,0 +1,48 @@ +Consider changing: + +``` +foo(); +bar(); +``` + +To: + +``` +if (true) { + foo(); +} +``` + +What we want: + +``` ++ if (true) { + foo(); +- bar(); ++ } +``` + +A longest-common-subsequence algorithm is wrong here. The longest +subsequence is five tokens: + +``` +( ) ( ) ; +``` + +which leads to: + +``` ++if+ (+true+) +{+ + +foo+(); + -bar-(); ++}+ +``` + +so we claim `foo` is added. We want the following *four* tokens to be +preserved: + +``` +foo ( ) ; +``` + +Proposed solution: advance on both sides, keep first match. |