1
- /*Package difflib is a partial port of Python difflib module.
1
+ /*
2
+ Package difflib is a partial port of Python difflib module.
2
3
3
4
Original source: https://github.com/pmezard/go-difflib
4
5
5
6
This file is trimmed to only the parts used by this repository.
6
7
*/
7
8
package difflib // import "gotest.tools/v3/internal/difflib"
8
9
9
- func min (a , b int ) int {
10
+ func minInt (a , b int ) int {
10
11
if a < b {
11
12
return a
12
13
}
13
14
return b
14
15
}
15
16
16
- func max (a , b int ) int {
17
+ func maxInt (a , b int ) int {
17
18
if a > b {
18
19
return a
19
20
}
@@ -170,12 +171,15 @@ func (m *SequenceMatcher) isBJunk(s string) bool {
170
171
// If IsJunk is not defined:
171
172
//
172
173
// Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
173
- // alo <= i <= i+k <= ahi
174
- // blo <= j <= j+k <= bhi
174
+ //
175
+ // alo <= i <= i+k <= ahi
176
+ // blo <= j <= j+k <= bhi
177
+ //
175
178
// and for all (i',j',k') meeting those conditions,
176
- // k >= k'
177
- // i <= i'
178
- // and if i == i', j <= j'
179
+ //
180
+ // k >= k'
181
+ // i <= i'
182
+ // and if i == i', j <= j'
179
183
//
180
184
// In other words, of all maximal matching blocks, return one that
181
185
// starts earliest in a, and of all those maximal matching blocks that
@@ -393,12 +397,12 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
393
397
if codes [0 ].Tag == 'e' {
394
398
c := codes [0 ]
395
399
i1 , i2 , j1 , j2 := c .I1 , c .I2 , c .J1 , c .J2
396
- codes [0 ] = OpCode {c .Tag , max (i1 , i2 - n ), i2 , max (j1 , j2 - n ), j2 }
400
+ codes [0 ] = OpCode {c .Tag , maxInt (i1 , i2 - n ), i2 , maxInt (j1 , j2 - n ), j2 }
397
401
}
398
402
if codes [len (codes )- 1 ].Tag == 'e' {
399
403
c := codes [len (codes )- 1 ]
400
404
i1 , i2 , j1 , j2 := c .I1 , c .I2 , c .J1 , c .J2
401
- codes [len (codes )- 1 ] = OpCode {c .Tag , i1 , min (i2 , i1 + n ), j1 , min (j2 , j1 + n )}
405
+ codes [len (codes )- 1 ] = OpCode {c .Tag , i1 , minInt (i2 , i1 + n ), j1 , minInt (j2 , j1 + n )}
402
406
}
403
407
nn := n + n
404
408
groups := [][]OpCode {}
@@ -408,11 +412,11 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
408
412
// End the current group and start a new one whenever
409
413
// there is a large range with no changes.
410
414
if c .Tag == 'e' && i2 - i1 > nn {
411
- group = append (group , OpCode {c .Tag , i1 , min (i2 , i1 + n ),
412
- j1 , min (j2 , j1 + n )})
415
+ group = append (group , OpCode {c .Tag , i1 , minInt (i2 , i1 + n ),
416
+ j1 , minInt (j2 , j1 + n )})
413
417
groups = append (groups , group )
414
418
group = []OpCode {}
415
- i1 , j1 = max (i1 , i2 - n ), max (j1 , j2 - n )
419
+ i1 , j1 = maxInt (i1 , i2 - n ), maxInt (j1 , j2 - n )
416
420
}
417
421
group = append (group , OpCode {c .Tag , i1 , i2 , j1 , j2 })
418
422
}
0 commit comments