Debian Codegraph @

internal/diff/lcs/old.go

raw symbols SCIP
1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/
6
7 // TODO(adonovan): remove unclear references to "old" in this package.
8
9 import (
10 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
11 )
12
13 // A Diff is a replacement of a portion of A by a portion of B.
14 type Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff# struct {
15 Startscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff#Start., Endscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff#End. int // offsets of portion to delete in A
16 ReplStartscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff#ReplStart., ReplEndscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff#ReplEnd. int // offset of replacement text in B
17 }
18
19 // DiffBytes returns the differences between two byte sequences.
20 // It does not respect rune boundaries.
21 func DiffBytesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/DiffBytes().(a, b []byte) []Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff# { return diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diff().(bytesSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/bytesSeqs#{a, b}) }
22
23 // DiffRunes returns the differences between two rune sequences.
24 func DiffRunesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/DiffRunes().(a, b []rune) []Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff# { return diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diff().(runesSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/runesSeqs#{a, b}) }
25
26 // DiffLines returns the differences between two string sequences.
27 func DiffLinesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/DiffLines().(a, b []string) []Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff# { return diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diff().(linesSeqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/linesSeqs#{a, b}) }
28
29 // A limit on how deeply the LCS algorithm should search. The value is just a guess.
30 var maxDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/maxDiffs. = 100
31
32 func diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diff().(seqs sequencesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/sequences#) []Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff# {
33 diff, _ := computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(seqs, twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided()., maxDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/maxDiffs./2)
34 return diff
35 }
36
37 // compute computes the list of differences between two sequences,
38 // along with the LCS. It is exercised directly by tests.
39 // The algorithm is one of {forward, backward, twosided}.
40 func computescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/compute().(seqs sequencesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/sequences#, algo func(*editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#, limit int) ([]Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff#, lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#) {
41 if limit <= 0 {
42 limit = 1 << 25 // effectively infinity
43 }
44 alen, blen := seqs.lengthsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/sequences#lengths.()
45 g := &editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#{
46 seqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#seqs.: seqs,
47 vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf.: newtriangscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/newtriang().(limit),
48 vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb.: newtriangscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/newtriang().(limit),
49 limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.: limit,
50 uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux.: alen,
51 uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy.: blen,
52 deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.: alen - blen,
53 }
54 lcs := algo(g)
55 diffs := lcs.toDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#toDiffs().(alen, blen)
56 return diffs, lcs
57 }
58
59 // editGraph carries the information for computing the lcs of two sequences.
60 type editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph# struct {
61 seqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#seqs. sequencesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/sequences#
62 vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf., vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb. labelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label# // forward and backward labels
63
64 limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. int // maximal value of D
65 // the bounding rectangle of the current edit graph
66 lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx., lyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ly., uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux., uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. int
67 deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta. int // common subexpression: (ux-lx)-(uy-ly)
68 }
69
70 // toDiffs converts an LCS to a list of edits.
71 func (lcs lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#) toDiffsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#toDiffs().(alen, blen int) []Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff# {
72 var diffs []Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff#
73 var pa, pb int // offsets in a, b
74 for _, l := range lcs {
75 if pa < l.Xscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diag#X. || pb < l.Yscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diag#Y. {
76 diffs = append(diffs, Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff#{pa, l.Xscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diag#X., pb, l.Yscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diag#Y.})
77 }
78 pa = l.Xscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diag#X. + l.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diag#Len.
79 pb = l.Yscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diag#Y. + l.Lenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/diag#Len.
80 }
81 if pa < alen || pb < blen {
82 diffs = append(diffs, Diffscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/Diff#{pa, alen, pb, blen})
83 }
84 return diffs
85 }
86
87 // --- FORWARD ---
88
89 // fdone decides if the forward path has reached the upper right
90 // corner of the rectangle. If so, it also returns the computed lcs.
91 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) fdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#fdone().(D, k int) (bool, lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#) {
92 // x, y, k are relative to the rectangle
93 x := e.vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(D, k)
94 y := x - k
95 if x == e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. && y == e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. {
96 return true, e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(D, k)
97 }
98 return false, nil
99 }
100
101 // run the forward algorithm, until success or up to the limit on D.
102 func forwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/forward().(e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs# {
103 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(0, 0, e.lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx.)
104 if ok, ans := e.fdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#fdone().(0, 0); ok {
105 return ans
106 }
107 // from D to D+1
108 for D := range e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. {
109 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(D+1, -(D + 1), e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, -D))
110 if ok, ans := e.fdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#fdone().(D+1, -(D + 1)); ok {
111 return ans
112 }
113 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(D+1, D+1, e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, D)+1)
114 if ok, ans := e.fdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#fdone().(D+1, D+1); ok {
115 return ans
116 }
117 for k := -D + 1; k <= D-1; k += 2 {
118 // these are tricky and easy to get backwards
119 lookv := e.lookForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookForward().(k, e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, k-1)+1)
120 lookh := e.lookForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookForward().(k, e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, k+1))
121 if lookv > lookh {
122 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(D+1, k, lookv)
123 } else {
124 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(D+1, k, lookh)
125 }
126 if ok, ans := e.fdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#fdone().(D+1, k); ok {
127 return ans
128 }
129 }
130 }
131 // D is too large
132 // find the D path with maximal x+y inside the rectangle and
133 // use that to compute the found part of the lcs
134 kmax := -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. - 1
135 diagmax := -1
136 for k := -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.; k <= e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.; k += 2 {
137 x := e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit., k)
138 y := x - k
139 if x+y > diagmax && x <= e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. && y <= e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. {
140 diagmax, kmax = x+y, k
141 }
142 }
143 return e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit., kmax)
144 }
145
146 // recover the lcs by backtracking from the farthest point reached
147 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(D, k int) lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs# {
148 var ans lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#
149 for x := e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, k); x != 0 || x-k != 0; {
150 if okscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/ok().(D-1, k-1) && x-1 == e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D-1, k-1) {
151 // if (x-1,y) is labelled D-1, x--,D--,k--,continue
152 D, k, x = D-1, k-1, x-1
153 continue
154 } else if okscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/ok().(D-1, k+1) && x == e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D-1, k+1) {
155 // if (x,y-1) is labelled D-1, x, D--,k++, continue
156 D, k = D-1, k+1
157 continue
158 }
159 // if (x-1,y-1)--(x,y) is a diagonal, prepend,x--,y--, continue
160 y := x - k
161 ans = ans.prependscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#prepend().(x+e.lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx.-1, y+e.lyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ly.-1)
162 x--
163 }
164 return ans
165 }
166
167 // start at (x,y), go up the diagonal as far as possible,
168 // and label the result with d
169 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) lookForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookForward().(k, relx int) int {
170 rely := relx - k
171 x, y := relx+e.lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx., rely+e.lyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ly.
172 if x < e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. && y < e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. {
173 x += e.seqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#seqs..commonPrefixLenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/sequences#commonPrefixLen.(x, e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux., y, e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy.)
174 }
175 return x
176 }
177
178 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(d, k, relx int) {
179 x := e.lookForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookForward().(k, relx)
180 e.vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf..setscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#set().(d, k, x-e.lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx.)
181 }
182
183 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(d, k int) int {
184 x := e.vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(d, k)
185 return x
186 }
187
188 // --- BACKWARD ---
189
190 // bdone decides if the backward path has reached the lower left corner
191 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) bdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#bdone().(D, k int) (bool, lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#) {
192 // x, y, k are relative to the rectangle
193 x := e.vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(D, k)
194 y := x - (k + e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)
195 if x == 0 && y == 0 {
196 return true, e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(D, k)
197 }
198 return false, nil
199 }
200
201 // run the backward algorithm, until success or up to the limit on D.
202 // (used only by tests)
203 func backwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/backward().(e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs# {
204 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(0, 0, e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux.)
205 if ok, ans := e.bdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#bdone().(0, 0); ok {
206 return ans
207 }
208 // from D to D+1
209 for D := range e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. {
210 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(D+1, -(D + 1), e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, -D)-1)
211 if ok, ans := e.bdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#bdone().(D+1, -(D + 1)); ok {
212 return ans
213 }
214 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(D+1, D+1, e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, D))
215 if ok, ans := e.bdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#bdone().(D+1, D+1); ok {
216 return ans
217 }
218 for k := -D + 1; k <= D-1; k += 2 {
219 // these are tricky and easy to get wrong
220 lookv := e.lookBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookBackward().(k, e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, k-1))
221 lookh := e.lookBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookBackward().(k, e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, k+1)-1)
222 if lookv < lookh {
223 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(D+1, k, lookv)
224 } else {
225 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(D+1, k, lookh)
226 }
227 if ok, ans := e.bdonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#bdone().(D+1, k); ok {
228 return ans
229 }
230 }
231 }
232
233 // D is too large
234 // find the D path with minimal x+y inside the rectangle and
235 // use that to compute the part of the lcs found
236 kmax := -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. - 1
237 diagmin := 1 << 25
238 for k := -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.; k <= e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.; k += 2 {
239 x := e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit., k)
240 y := x - (k + e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)
241 if x+y < diagmin && x >= 0 && y >= 0 {
242 diagmin, kmax = x+y, k
243 }
244 }
245 if kmax < -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. {
246 panic(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("no paths when limit=%d?", e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.))
247 }
248 return e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit., kmax)
249 }
250
251 // recover the lcs by backtracking
252 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(D, k int) lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs# {
253 var ans lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#
254 for x := e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, k); x != e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. || x-(k+e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.) != e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy.; {
255 if okscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/ok().(D-1, k-1) && x == e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D-1, k-1) {
256 // D--, k--, x unchanged
257 D, k = D-1, k-1
258 continue
259 } else if okscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/ok().(D-1, k+1) && x+1 == e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D-1, k+1) {
260 // D--, k++, x++
261 D, k, x = D-1, k+1, x+1
262 continue
263 }
264 y := x - (k + e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)
265 ans = ans.appendscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#append().(x+e.lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx., y+e.lyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ly.)
266 x++
267 }
268 return ans
269 }
270
271 // start at (x,y), go down the diagonal as far as possible,
272 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) lookBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookBackward().(k, relx int) int {
273 rely := relx - (k + e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.) // forward k = k + e.delta
274 x, y := relx+e.lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx., rely+e.lyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ly.
275 if x > 0 && y > 0 {
276 x -= e.seqsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#seqs..commonSuffixLenscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/sequences#commonSuffixLen.(0, x, 0, y)
277 }
278 return x
279 }
280
281 // convert to rectangle, and label the result with d
282 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(d, k, relx int) {
283 x := e.lookBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookBackward().(k, relx)
284 e.vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb..setscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#set().(d, k, x-e.lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx.)
285 }
286
287 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(d, k int) int {
288 x := e.vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(d, k)
289 return x
290 }
291
292 // -- TWOSIDED ---
293
294 func twosidedscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/twosided().(e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs# {
295 // The termination condition could be improved, as either the forward
296 // or backward pass could succeed before Myers' Lemma applies.
297 // Aside from questions of efficiency (is the extra testing cost-effective)
298 // this is more likely to matter when e.limit is reached.
299 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(0, 0, e.lxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lx.)
300 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(0, 0, e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux.)
301
302 // from D to D+1
303 for D := range e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. {
304 // just finished a backwards pass, so check
305 if got, ok := e.twoDonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#twoDone().(D, D); ok {
306 return e.twolcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#twolcs().(D, D, got)
307 }
308 // do a forwards pass (D to D+1)
309 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(D+1, -(D + 1), e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, -D))
310 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(D+1, D+1, e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, D)+1)
311 for k := -D + 1; k <= D-1; k += 2 {
312 // these are tricky and easy to get backwards
313 lookv := e.lookForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookForward().(k, e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, k-1)+1)
314 lookh := e.lookForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookForward().(k, e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(D, k+1))
315 if lookv > lookh {
316 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(D+1, k, lookv)
317 } else {
318 e.setForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setForward().(D+1, k, lookh)
319 }
320 }
321 // just did a forward pass, so check
322 if got, ok := e.twoDonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#twoDone().(D+1, D); ok {
323 return e.twolcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#twolcs().(D+1, D, got)
324 }
325 // do a backward pass, D to D+1
326 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(D+1, -(D + 1), e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, -D)-1)
327 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(D+1, D+1, e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, D))
328 for k := -D + 1; k <= D-1; k += 2 {
329 // these are tricky and easy to get wrong
330 lookv := e.lookBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookBackward().(k, e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, k-1))
331 lookh := e.lookBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#lookBackward().(k, e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(D, k+1)-1)
332 if lookv < lookh {
333 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(D+1, k, lookv)
334 } else {
335 e.setBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#setBackward().(D+1, k, lookh)
336 }
337 }
338 }
339
340 // D too large. combine a forward and backward partial lcs
341 // first, a forward one
342 kmax := -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. - 1
343 diagmax := -1
344 for k := -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.; k <= e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.; k += 2 {
345 x := e.getForwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getForward().(e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit., k)
346 y := x - k
347 if x+y > diagmax && x <= e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. && y <= e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. {
348 diagmax, kmax = x+y, k
349 }
350 }
351 if kmax < -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. {
352 panic(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("no forward paths when limit=%d?", e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.))
353 }
354 lcs := e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit., kmax)
355 // now a backward one
356 // find the D path with minimal x+y inside the rectangle and
357 // use that to compute the lcs
358 diagmin := 1 << 25 // infinity
359 for k := -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.; k <= e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.; k += 2 {
360 x := e.getBackwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#getBackward().(e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit., k)
361 y := x - (k + e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)
362 if x+y < diagmin && x >= 0 && y >= 0 {
363 diagmin, kmax = x+y, k
364 }
365 }
366 if kmax < -e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit. {
367 panic(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("no backward paths when limit=%d?", e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit.))
368 }
369 lcs = append(lcs, e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(e.limitscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#limit., kmax)...)
370 // These may overlap (e.forwardlcs and e.backwardlcs return sorted lcs)
371 ans := lcs.fixscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#fix().()
372 return ans
373 }
374
375 // Does Myers' Lemma apply?
376 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) twoDonescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#twoDone().(df, db int) (int, bool) {
377 if (df+db+e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)%2 != 0 {
378 return 0, false // diagonals cannot overlap
379 }
380 kmin := max(-df, -db+e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)
381 kmax := min(df, db+e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)
382 for k := kmin; k <= kmax; k += 2 {
383 x := e.vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(df, k)
384 u := e.vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(db, k-e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)
385 if u <= x {
386 // is it worth looking at all the other k?
387 for l := k; l <= kmax; l += 2 {
388 x := e.vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(df, l)
389 y := x - l
390 u := e.vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(db, l-e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.)
391 v := u - l
392 if x == u || u == 0 || v == 0 || y == e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. || x == e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. {
393 return l, true
394 }
395 }
396 return k, true
397 }
398 }
399 return 0, false
400 }
401
402 func (e *editGraphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#) twolcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#twolcs().(df, db, kf int) lcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs# {
403 // db==df || db+1==df
404 x := e.vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(df, kf)
405 y := x - kf
406 kb := kf - e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.
407 u := e.vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(db, kb)
408 v := u - kf
409
410 // Myers proved there is a df-path from (0,0) to (u,v)
411 // and a db-path from (x,y) to (N,M).
412 // In the first case the overall path is the forward path
413 // to (u,v) followed by the backward path to (N,M).
414 // In the second case the path is the backward path to (x,y)
415 // followed by the forward path to (x,y) from (0,0).
416
417 // Look for some special cases to avoid computing either of these paths.
418 if x == u {
419 // "babaab" "cccaba"
420 // already patched together
421 lcs := e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(df, kf)
422 lcs = append(lcs, e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(db, kb)...)
423 return lcs.sortscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#sort().()
424 }
425
426 // is (u-1,v) or (u,v-1) labelled df-1?
427 // if so, that forward df-1-path plus a horizontal or vertical edge
428 // is the df-path to (u,v), then plus the db-path to (N,M)
429 if u > 0 && okscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/ok().(df-1, u-1-v) && e.vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(df-1, u-1-v) == u-1 {
430 // "aabbab" "cbcabc"
431 lcs := e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(df-1, u-1-v)
432 lcs = append(lcs, e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(db, kb)...)
433 return lcs.sortscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#sort().()
434 }
435 if v > 0 && okscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/ok().(df-1, (u-(v-1))) && e.vfscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vf..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(df-1, u-(v-1)) == u {
436 // "abaabb" "bcacab"
437 lcs := e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(df-1, u-(v-1))
438 lcs = append(lcs, e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(db, kb)...)
439 return lcs.sortscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#sort().()
440 }
441
442 // The path can't possibly contribute to the lcs because it
443 // is all horizontal or vertical edges
444 if u == 0 || v == 0 || x == e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. || y == e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. {
445 // "abaabb" "abaaaa"
446 if u == 0 || v == 0 {
447 return e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(db, kb)
448 }
449 return e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(df, kf)
450 }
451
452 // is (x+1,y) or (x,y+1) labelled db-1?
453 if x+1 <= e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. && okscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/ok().(db-1, x+1-y-e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.) && e.vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(db-1, x+1-y-e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.) == x+1 {
454 // "bababb" "baaabb"
455 lcs := e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(db-1, kb+1)
456 lcs = append(lcs, e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(df, kf)...)
457 return lcs.sortscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#sort().()
458 }
459 if y+1 <= e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. && okscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/ok().(db-1, x-(y+1)-e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.) && e.vbscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#vb..getscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/label#get().(db-1, x-(y+1)-e.deltascip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#delta.) == x {
460 // "abbbaa" "cabacc"
461 lcs := e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(db-1, kb-1)
462 lcs = append(lcs, e.forwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#forwardlcs().(df, kf)...)
463 return lcs.sortscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#sort().()
464 }
465
466 // need to compute another path
467 // "aabbaa" "aacaba"
468 lcs := e.backwardlcsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#backwardlcs().(db, kb)
469 oldx, oldy := e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux., e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy.
470 e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux. = u
471 e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. = v
472 lcs = append(lcs, forwardscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/forward().(e)...)
473 e.uxscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#ux., e.uyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/editGraph#uy. = oldx, oldy
474 return lcs.sortscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/diff/lcs`/lcs#sort().()
475 }