Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
12e5b2f3
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
12e5b2f3
编写于
10月 16, 2019
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
💄
上级
44811c09
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
54 addition
and
58 deletion
+54
-58
src/vs/base/common/diff/diff.ts
src/vs/base/common/diff/diff.ts
+54
-58
未找到文件。
src/vs/base/common/diff/diff.ts
浏览文件 @
12e5b2f3
...
@@ -112,11 +112,9 @@ export class MyArray {
...
@@ -112,11 +112,9 @@ export class MyArray {
// Our total memory usage for storing history is (worst-case):
// Our total memory usage for storing history is (worst-case):
// 2 * [(MaxDifferencesHistory + 1) * (MaxDifferencesHistory + 1) - 1] * sizeof(int)
// 2 * [(MaxDifferencesHistory + 1) * (MaxDifferencesHistory + 1) - 1] * sizeof(int)
// 2 * [1448*1448 - 1] * 4 = 16773624 = 16MB
// 2 * [1448*1448 - 1] * 4 = 16773624 = 16MB
let
MaxDifferencesHistory
=
1447
;
const
enum
LocalConstants
{
//let MaxDifferencesHistory = 100;
MaxDifferencesHistory
=
1447
}
/**
/**
* A utility class which helps to create the set of DiffChanges from
* A utility class which helps to create the set of DiffChanges from
...
@@ -309,8 +307,8 @@ export class LcsDiff {
...
@@ -309,8 +307,8 @@ export class LcsDiff {
* @returns An array of the differences between the two input sequences.
* @returns An array of the differences between the two input sequences.
*/
*/
private
_ComputeDiff
(
originalStart
:
number
,
originalEnd
:
number
,
modifiedStart
:
number
,
modifiedEnd
:
number
,
pretty
:
boolean
):
DiffChange
[]
{
private
_ComputeDiff
(
originalStart
:
number
,
originalEnd
:
number
,
modifiedStart
:
number
,
modifiedEnd
:
number
,
pretty
:
boolean
):
DiffChange
[]
{
le
t
quitEarlyArr
=
[
false
];
cons
t
quitEarlyArr
=
[
false
];
le
t
changes
=
this
.
ComputeDiffRecursive
(
originalStart
,
originalEnd
,
modifiedStart
,
modifiedEnd
,
quitEarlyArr
);
cons
t
changes
=
this
.
ComputeDiffRecursive
(
originalStart
,
originalEnd
,
modifiedStart
,
modifiedEnd
,
quitEarlyArr
);
if
(
pretty
)
{
if
(
pretty
)
{
// We have to clean up the computed diff to be more intuitive
// We have to clean up the computed diff to be more intuitive
...
@@ -372,11 +370,12 @@ export class LcsDiff {
...
@@ -372,11 +370,12 @@ export class LcsDiff {
}
}
// This problem can be solved using the Divide-And-Conquer technique.
// This problem can be solved using the Divide-And-Conquer technique.
let
midOriginalArr
=
[
0
],
midModifiedArr
=
[
0
];
const
midOriginalArr
=
[
0
];
let
result
=
this
.
ComputeRecursionPoint
(
originalStart
,
originalEnd
,
modifiedStart
,
modifiedEnd
,
midOriginalArr
,
midModifiedArr
,
quitEarlyArr
);
const
midModifiedArr
=
[
0
];
const
result
=
this
.
ComputeRecursionPoint
(
originalStart
,
originalEnd
,
modifiedStart
,
modifiedEnd
,
midOriginalArr
,
midModifiedArr
,
quitEarlyArr
);
le
t
midOriginal
=
midOriginalArr
[
0
];
cons
t
midOriginal
=
midOriginalArr
[
0
];
le
t
midModified
=
midModifiedArr
[
0
];
cons
t
midModified
=
midModifiedArr
[
0
];
if
(
result
!==
null
)
{
if
(
result
!==
null
)
{
// Result is not-null when there was enough memory to compute the changes while
// Result is not-null when there was enough memory to compute the changes while
...
@@ -388,7 +387,7 @@ export class LcsDiff {
...
@@ -388,7 +387,7 @@ export class LcsDiff {
// Second Half: (midOriginal + 1, minModified + 1) to (originalEnd, modifiedEnd)
// Second Half: (midOriginal + 1, minModified + 1) to (originalEnd, modifiedEnd)
// NOTE: ComputeDiff() is inclusive, therefore the second range starts on the next point
// NOTE: ComputeDiff() is inclusive, therefore the second range starts on the next point
le
t
leftChanges
=
this
.
ComputeDiffRecursive
(
originalStart
,
midOriginal
,
modifiedStart
,
midModified
,
quitEarlyArr
);
cons
t
leftChanges
=
this
.
ComputeDiffRecursive
(
originalStart
,
midOriginal
,
modifiedStart
,
midModified
,
quitEarlyArr
);
let
rightChanges
:
DiffChange
[]
=
[];
let
rightChanges
:
DiffChange
[]
=
[];
if
(
!
quitEarlyArr
[
0
])
{
if
(
!
quitEarlyArr
[
0
])
{
...
@@ -415,8 +414,10 @@ export class LcsDiff {
...
@@ -415,8 +414,10 @@ export class LcsDiff {
forwardPoints
:
Int32Array
,
reversePoints
:
Int32Array
,
forwardPoints
:
Int32Array
,
reversePoints
:
Int32Array
,
originalIndex
:
number
,
originalEnd
:
number
,
midOriginalArr
:
number
[],
originalIndex
:
number
,
originalEnd
:
number
,
midOriginalArr
:
number
[],
modifiedIndex
:
number
,
modifiedEnd
:
number
,
midModifiedArr
:
number
[],
modifiedIndex
:
number
,
modifiedEnd
:
number
,
midModifiedArr
:
number
[],
deltaIsEven
:
boolean
,
quitEarlyArr
:
boolean
[]):
DiffChange
[]
{
deltaIsEven
:
boolean
,
quitEarlyArr
:
boolean
[]
let
forwardChanges
:
DiffChange
[]
|
null
=
null
,
reverseChanges
:
DiffChange
[]
|
null
=
null
;
):
DiffChange
[]
{
let
forwardChanges
:
DiffChange
[]
|
null
=
null
;
let
reverseChanges
:
DiffChange
[]
|
null
=
null
;
// First, walk backward through the forward diagonals history
// First, walk backward through the forward diagonals history
let
changeHelper
=
new
DiffChangeHelper
();
let
changeHelper
=
new
DiffChangeHelper
();
...
@@ -425,11 +426,10 @@ export class LcsDiff {
...
@@ -425,11 +426,10 @@ export class LcsDiff {
let
diagonalRelative
=
(
midOriginalArr
[
0
]
-
midModifiedArr
[
0
])
-
diagonalForwardOffset
;
let
diagonalRelative
=
(
midOriginalArr
[
0
]
-
midModifiedArr
[
0
])
-
diagonalForwardOffset
;
let
lastOriginalIndex
=
Constants
.
MIN_SAFE_SMALL_INTEGER
;
let
lastOriginalIndex
=
Constants
.
MIN_SAFE_SMALL_INTEGER
;
let
historyIndex
=
this
.
m_forwardHistory
.
length
-
1
;
let
historyIndex
=
this
.
m_forwardHistory
.
length
-
1
;
let
diagonal
:
number
;
do
{
do
{
// Get the diagonal index from the relative diagonal number
// Get the diagonal index from the relative diagonal number
diagonal
=
diagonalRelative
+
diagonalForwardBase
;
const
diagonal
=
diagonalRelative
+
diagonalForwardBase
;
// Figure out where we came from
// Figure out where we came from
if
(
diagonal
===
diagonalMin
||
(
diagonal
<
diagonalMax
&&
forwardPoints
[
diagonal
-
1
]
<
forwardPoints
[
diagonal
+
1
]))
{
if
(
diagonal
===
diagonalMin
||
(
diagonal
<
diagonalMax
&&
forwardPoints
[
diagonal
-
1
]
<
forwardPoints
[
diagonal
+
1
]))
{
...
@@ -474,7 +474,7 @@ export class LcsDiff {
...
@@ -474,7 +474,7 @@ export class LcsDiff {
let
modifiedStartPoint
=
midModifiedArr
[
0
]
+
1
;
let
modifiedStartPoint
=
midModifiedArr
[
0
]
+
1
;
if
(
forwardChanges
!==
null
&&
forwardChanges
.
length
>
0
)
{
if
(
forwardChanges
!==
null
&&
forwardChanges
.
length
>
0
)
{
le
t
lastForwardChange
=
forwardChanges
[
forwardChanges
.
length
-
1
];
cons
t
lastForwardChange
=
forwardChanges
[
forwardChanges
.
length
-
1
];
originalStartPoint
=
Math
.
max
(
originalStartPoint
,
lastForwardChange
.
getOriginalEnd
());
originalStartPoint
=
Math
.
max
(
originalStartPoint
,
lastForwardChange
.
getOriginalEnd
());
modifiedStartPoint
=
Math
.
max
(
modifiedStartPoint
,
lastForwardChange
.
getModifiedEnd
());
modifiedStartPoint
=
Math
.
max
(
modifiedStartPoint
,
lastForwardChange
.
getModifiedEnd
());
}
}
...
@@ -494,7 +494,7 @@ export class LcsDiff {
...
@@ -494,7 +494,7 @@ export class LcsDiff {
do
{
do
{
// Get the diagonal index from the relative diagonal number
// Get the diagonal index from the relative diagonal number
diagonal
=
diagonalRelative
+
diagonalReverseBase
;
const
diagonal
=
diagonalRelative
+
diagonalReverseBase
;
// Figure out where we came from
// Figure out where we came from
if
(
diagonal
===
diagonalMin
||
(
diagonal
<
diagonalMax
&&
reversePoints
[
diagonal
-
1
]
>=
reversePoints
[
diagonal
+
1
]))
{
if
(
diagonal
===
diagonalMin
||
(
diagonal
<
diagonalMax
&&
reversePoints
[
diagonal
-
1
]
>=
reversePoints
[
diagonal
+
1
]))
{
...
@@ -555,7 +555,6 @@ export class LcsDiff {
...
@@ -555,7 +555,6 @@ export class LcsDiff {
let
originalIndex
=
0
,
modifiedIndex
=
0
;
let
originalIndex
=
0
,
modifiedIndex
=
0
;
let
diagonalForwardStart
=
0
,
diagonalForwardEnd
=
0
;
let
diagonalForwardStart
=
0
,
diagonalForwardEnd
=
0
;
let
diagonalReverseStart
=
0
,
diagonalReverseEnd
=
0
;
let
diagonalReverseStart
=
0
,
diagonalReverseEnd
=
0
;
let
numDifferences
:
number
;
// To traverse the edit graph and produce the proper LCS, our actual
// To traverse the edit graph and produce the proper LCS, our actual
// start position is just outside the given boundary
// start position is just outside the given boundary
...
@@ -575,26 +574,26 @@ export class LcsDiff {
...
@@ -575,26 +574,26 @@ export class LcsDiff {
// The integer value in the cell represents the originalIndex of the furthest
// The integer value in the cell represents the originalIndex of the furthest
// reaching point found so far that ends in that diagonal.
// reaching point found so far that ends in that diagonal.
// The modifiedIndex can be computed mathematically from the originalIndex and the diagonal number.
// The modifiedIndex can be computed mathematically from the originalIndex and the diagonal number.
le
t
maxDifferences
=
(
originalEnd
-
originalStart
)
+
(
modifiedEnd
-
modifiedStart
);
cons
t
maxDifferences
=
(
originalEnd
-
originalStart
)
+
(
modifiedEnd
-
modifiedStart
);
le
t
numDiagonals
=
maxDifferences
+
1
;
cons
t
numDiagonals
=
maxDifferences
+
1
;
le
t
forwardPoints
=
new
Int32Array
(
numDiagonals
);
cons
t
forwardPoints
=
new
Int32Array
(
numDiagonals
);
le
t
reversePoints
=
new
Int32Array
(
numDiagonals
);
cons
t
reversePoints
=
new
Int32Array
(
numDiagonals
);
// diagonalForwardBase: Index into forwardPoints of the diagonal which passes through (originalStart, modifiedStart)
// diagonalForwardBase: Index into forwardPoints of the diagonal which passes through (originalStart, modifiedStart)
// diagonalReverseBase: Index into reversePoints of the diagonal which passes through (originalEnd, modifiedEnd)
// diagonalReverseBase: Index into reversePoints of the diagonal which passes through (originalEnd, modifiedEnd)
le
t
diagonalForwardBase
=
(
modifiedEnd
-
modifiedStart
);
cons
t
diagonalForwardBase
=
(
modifiedEnd
-
modifiedStart
);
le
t
diagonalReverseBase
=
(
originalEnd
-
originalStart
);
cons
t
diagonalReverseBase
=
(
originalEnd
-
originalStart
);
// diagonalForwardOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
// diagonalForwardOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
// diagonal number (relative to diagonalForwardBase)
// diagonal number (relative to diagonalForwardBase)
// diagonalReverseOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
// diagonalReverseOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
// diagonal number (relative to diagonalReverseBase)
// diagonal number (relative to diagonalReverseBase)
le
t
diagonalForwardOffset
=
(
originalStart
-
modifiedStart
);
cons
t
diagonalForwardOffset
=
(
originalStart
-
modifiedStart
);
le
t
diagonalReverseOffset
=
(
originalEnd
-
modifiedEnd
);
cons
t
diagonalReverseOffset
=
(
originalEnd
-
modifiedEnd
);
// delta: The difference between the end diagonal and the start diagonal. This is used to relate diagonal numbers
// delta: The difference between the end diagonal and the start diagonal. This is used to relate diagonal numbers
// relative to the start diagonal with diagonal numbers relative to the end diagonal.
// relative to the start diagonal with diagonal numbers relative to the end diagonal.
// The Even/Oddn-ness of this delta is important for determining when we should check for overlap
// The Even/Oddn-ness of this delta is important for determining when we should check for overlap
le
t
delta
=
diagonalReverseBase
-
diagonalForwardBase
;
cons
t
delta
=
diagonalReverseBase
-
diagonalForwardBase
;
le
t
deltaIsEven
=
(
delta
%
2
===
0
);
cons
t
deltaIsEven
=
(
delta
%
2
===
0
);
// Here we set up the start and end points as the furthest points found so far
// Here we set up the start and end points as the furthest points found so far
// in both the forward and reverse directions, respectively
// in both the forward and reverse directions, respectively
...
@@ -613,15 +612,14 @@ export class LcsDiff {
...
@@ -613,15 +612,14 @@ export class LcsDiff {
// away from the reference diagonal (which is diagonalForwardBase for forward, diagonalReverseBase for reverse).
// away from the reference diagonal (which is diagonalForwardBase for forward, diagonalReverseBase for reverse).
// --We extend on even diagonals (relative to the reference diagonal) only when numDifferences
// --We extend on even diagonals (relative to the reference diagonal) only when numDifferences
// is even and odd diagonals only when numDifferences is odd.
// is even and odd diagonals only when numDifferences is odd.
let
diagonal
:
number
,
tempOriginalIndex
:
number
;
for
(
let
numDifferences
=
1
;
numDifferences
<=
(
maxDifferences
/
2
)
+
1
;
numDifferences
++
)
{
for
(
numDifferences
=
1
;
numDifferences
<=
(
maxDifferences
/
2
)
+
1
;
numDifferences
++
)
{
let
furthestOriginalIndex
=
0
;
let
furthestOriginalIndex
=
0
;
let
furthestModifiedIndex
=
0
;
let
furthestModifiedIndex
=
0
;
// Run the algorithm in the forward direction
// Run the algorithm in the forward direction
diagonalForwardStart
=
this
.
ClipDiagonalBound
(
diagonalForwardBase
-
numDifferences
,
numDifferences
,
diagonalForwardBase
,
numDiagonals
);
diagonalForwardStart
=
this
.
ClipDiagonalBound
(
diagonalForwardBase
-
numDifferences
,
numDifferences
,
diagonalForwardBase
,
numDiagonals
);
diagonalForwardEnd
=
this
.
ClipDiagonalBound
(
diagonalForwardBase
+
numDifferences
,
numDifferences
,
diagonalForwardBase
,
numDiagonals
);
diagonalForwardEnd
=
this
.
ClipDiagonalBound
(
diagonalForwardBase
+
numDifferences
,
numDifferences
,
diagonalForwardBase
,
numDiagonals
);
for
(
diagonal
=
diagonalForwardStart
;
diagonal
<=
diagonalForwardEnd
;
diagonal
+=
2
)
{
for
(
let
diagonal
=
diagonalForwardStart
;
diagonal
<=
diagonalForwardEnd
;
diagonal
+=
2
)
{
// STEP 1: We extend the furthest reaching point in the present diagonal
// STEP 1: We extend the furthest reaching point in the present diagonal
// by looking at the diagonals above and below and picking the one whose point
// by looking at the diagonals above and below and picking the one whose point
// is further away from the start point (originalStart, modifiedStart)
// is further away from the start point (originalStart, modifiedStart)
...
@@ -633,7 +631,7 @@ export class LcsDiff {
...
@@ -633,7 +631,7 @@ export class LcsDiff {
modifiedIndex
=
originalIndex
-
(
diagonal
-
diagonalForwardBase
)
-
diagonalForwardOffset
;
modifiedIndex
=
originalIndex
-
(
diagonal
-
diagonalForwardBase
)
-
diagonalForwardOffset
;
// Save the current originalIndex so we can test for false overlap in step 3
// Save the current originalIndex so we can test for false overlap in step 3
tempOriginalIndex
=
originalIndex
;
const
tempOriginalIndex
=
originalIndex
;
// STEP 2: We can continue to extend the furthest reaching point in the present diagonal
// STEP 2: We can continue to extend the furthest reaching point in the present diagonal
// so long as the elements are equal.
// so long as the elements are equal.
...
@@ -657,7 +655,7 @@ export class LcsDiff {
...
@@ -657,7 +655,7 @@ export class LcsDiff {
midOriginalArr
[
0
]
=
originalIndex
;
midOriginalArr
[
0
]
=
originalIndex
;
midModifiedArr
[
0
]
=
modifiedIndex
;
midModifiedArr
[
0
]
=
modifiedIndex
;
if
(
tempOriginalIndex
<=
reversePoints
[
diagonal
]
&&
MaxDifferencesHistory
>
0
&&
numDifferences
<=
(
MaxDifferencesHistory
+
1
))
{
if
(
tempOriginalIndex
<=
reversePoints
[
diagonal
]
&&
LocalConstants
.
MaxDifferencesHistory
>
0
&&
numDifferences
<=
(
LocalConstants
.
MaxDifferencesHistory
+
1
))
{
// BINGO! We overlapped, and we have the full trace in memory!
// BINGO! We overlapped, and we have the full trace in memory!
return
this
.
WALKTRACE
(
diagonalForwardBase
,
diagonalForwardStart
,
diagonalForwardEnd
,
diagonalForwardOffset
,
return
this
.
WALKTRACE
(
diagonalForwardBase
,
diagonalForwardStart
,
diagonalForwardEnd
,
diagonalForwardOffset
,
diagonalReverseBase
,
diagonalReverseStart
,
diagonalReverseEnd
,
diagonalReverseOffset
,
diagonalReverseBase
,
diagonalReverseStart
,
diagonalReverseEnd
,
diagonalReverseOffset
,
...
@@ -676,7 +674,7 @@ export class LcsDiff {
...
@@ -676,7 +674,7 @@ export class LcsDiff {
}
}
// Check to see if we should be quitting early, before moving on to the next iteration.
// Check to see if we should be quitting early, before moving on to the next iteration.
le
t
matchLengthOfLongest
=
((
furthestOriginalIndex
-
originalStart
)
+
(
furthestModifiedIndex
-
modifiedStart
)
-
numDifferences
)
/
2
;
cons
t
matchLengthOfLongest
=
((
furthestOriginalIndex
-
originalStart
)
+
(
furthestModifiedIndex
-
modifiedStart
)
-
numDifferences
)
/
2
;
if
(
this
.
ContinueProcessingPredicate
!==
null
&&
!
this
.
ContinueProcessingPredicate
(
furthestOriginalIndex
,
matchLengthOfLongest
))
{
if
(
this
.
ContinueProcessingPredicate
!==
null
&&
!
this
.
ContinueProcessingPredicate
(
furthestOriginalIndex
,
matchLengthOfLongest
))
{
// We can't finish, so skip ahead to generating a result from what we have.
// We can't finish, so skip ahead to generating a result from what we have.
...
@@ -686,7 +684,7 @@ export class LcsDiff {
...
@@ -686,7 +684,7 @@ export class LcsDiff {
midOriginalArr
[
0
]
=
furthestOriginalIndex
;
midOriginalArr
[
0
]
=
furthestOriginalIndex
;
midModifiedArr
[
0
]
=
furthestModifiedIndex
;
midModifiedArr
[
0
]
=
furthestModifiedIndex
;
if
(
matchLengthOfLongest
>
0
&&
MaxDifferencesHistory
>
0
&&
numDifferences
<=
(
MaxDifferencesHistory
+
1
))
{
if
(
matchLengthOfLongest
>
0
&&
LocalConstants
.
MaxDifferencesHistory
>
0
&&
numDifferences
<=
(
LocalConstants
.
MaxDifferencesHistory
+
1
))
{
// Enough of the history is in memory to walk it backwards
// Enough of the history is in memory to walk it backwards
return
this
.
WALKTRACE
(
diagonalForwardBase
,
diagonalForwardStart
,
diagonalForwardEnd
,
diagonalForwardOffset
,
return
this
.
WALKTRACE
(
diagonalForwardBase
,
diagonalForwardStart
,
diagonalForwardEnd
,
diagonalForwardOffset
,
diagonalReverseBase
,
diagonalReverseStart
,
diagonalReverseEnd
,
diagonalReverseOffset
,
diagonalReverseBase
,
diagonalReverseStart
,
diagonalReverseEnd
,
diagonalReverseOffset
,
...
@@ -713,7 +711,7 @@ export class LcsDiff {
...
@@ -713,7 +711,7 @@ export class LcsDiff {
// Run the algorithm in the reverse direction
// Run the algorithm in the reverse direction
diagonalReverseStart
=
this
.
ClipDiagonalBound
(
diagonalReverseBase
-
numDifferences
,
numDifferences
,
diagonalReverseBase
,
numDiagonals
);
diagonalReverseStart
=
this
.
ClipDiagonalBound
(
diagonalReverseBase
-
numDifferences
,
numDifferences
,
diagonalReverseBase
,
numDiagonals
);
diagonalReverseEnd
=
this
.
ClipDiagonalBound
(
diagonalReverseBase
+
numDifferences
,
numDifferences
,
diagonalReverseBase
,
numDiagonals
);
diagonalReverseEnd
=
this
.
ClipDiagonalBound
(
diagonalReverseBase
+
numDifferences
,
numDifferences
,
diagonalReverseBase
,
numDiagonals
);
for
(
diagonal
=
diagonalReverseStart
;
diagonal
<=
diagonalReverseEnd
;
diagonal
+=
2
)
{
for
(
let
diagonal
=
diagonalReverseStart
;
diagonal
<=
diagonalReverseEnd
;
diagonal
+=
2
)
{
// STEP 1: We extend the furthest reaching point in the present diagonal
// STEP 1: We extend the furthest reaching point in the present diagonal
// by looking at the diagonals above and below and picking the one whose point
// by looking at the diagonals above and below and picking the one whose point
// is further away from the start point (originalEnd, modifiedEnd)
// is further away from the start point (originalEnd, modifiedEnd)
...
@@ -725,7 +723,7 @@ export class LcsDiff {
...
@@ -725,7 +723,7 @@ export class LcsDiff {
modifiedIndex
=
originalIndex
-
(
diagonal
-
diagonalReverseBase
)
-
diagonalReverseOffset
;
modifiedIndex
=
originalIndex
-
(
diagonal
-
diagonalReverseBase
)
-
diagonalReverseOffset
;
// Save the current originalIndex so we can test for false overlap
// Save the current originalIndex so we can test for false overlap
tempOriginalIndex
=
originalIndex
;
const
tempOriginalIndex
=
originalIndex
;
// STEP 2: We can continue to extend the furthest reaching point in the present diagonal
// STEP 2: We can continue to extend the furthest reaching point in the present diagonal
// as long as the elements are equal.
// as long as the elements are equal.
...
@@ -743,7 +741,7 @@ export class LcsDiff {
...
@@ -743,7 +741,7 @@ export class LcsDiff {
midOriginalArr
[
0
]
=
originalIndex
;
midOriginalArr
[
0
]
=
originalIndex
;
midModifiedArr
[
0
]
=
modifiedIndex
;
midModifiedArr
[
0
]
=
modifiedIndex
;
if
(
tempOriginalIndex
>=
forwardPoints
[
diagonal
]
&&
MaxDifferencesHistory
>
0
&&
numDifferences
<=
(
MaxDifferencesHistory
+
1
))
{
if
(
tempOriginalIndex
>=
forwardPoints
[
diagonal
]
&&
LocalConstants
.
MaxDifferencesHistory
>
0
&&
numDifferences
<=
(
LocalConstants
.
MaxDifferencesHistory
+
1
))
{
// BINGO! We overlapped, and we have the full trace in memory!
// BINGO! We overlapped, and we have the full trace in memory!
return
this
.
WALKTRACE
(
diagonalForwardBase
,
diagonalForwardStart
,
diagonalForwardEnd
,
diagonalForwardOffset
,
return
this
.
WALKTRACE
(
diagonalForwardBase
,
diagonalForwardStart
,
diagonalForwardEnd
,
diagonalForwardOffset
,
diagonalReverseBase
,
diagonalReverseStart
,
diagonalReverseEnd
,
diagonalReverseOffset
,
diagonalReverseBase
,
diagonalReverseStart
,
diagonalReverseEnd
,
diagonalReverseOffset
,
...
@@ -762,7 +760,7 @@ export class LcsDiff {
...
@@ -762,7 +760,7 @@ export class LcsDiff {
}
}
// Save current vectors to history before the next iteration
// Save current vectors to history before the next iteration
if
(
numDifferences
<=
MaxDifferencesHistory
)
{
if
(
numDifferences
<=
LocalConstants
.
MaxDifferencesHistory
)
{
// We are allocating space for one extra int, which we fill with
// We are allocating space for one extra int, which we fill with
// the index of the diagonal base index
// the index of the diagonal base index
let
temp
=
new
Int32Array
(
diagonalForwardEnd
-
diagonalForwardStart
+
2
);
let
temp
=
new
Int32Array
(
diagonalForwardEnd
-
diagonalForwardStart
+
2
);
...
@@ -778,8 +776,6 @@ export class LcsDiff {
...
@@ -778,8 +776,6 @@ export class LcsDiff {
}
}
// If we got here, then we have the full trace in history. We just have to convert it to a change list
// If we got here, then we have the full trace in history. We just have to convert it to a change list
// NOTE: This part is a bit messy
// NOTE: This part is a bit messy
return
this
.
WALKTRACE
(
diagonalForwardBase
,
diagonalForwardStart
,
diagonalForwardEnd
,
diagonalForwardOffset
,
return
this
.
WALKTRACE
(
diagonalForwardBase
,
diagonalForwardStart
,
diagonalForwardEnd
,
diagonalForwardOffset
,
...
@@ -849,8 +845,8 @@ export class LcsDiff {
...
@@ -849,8 +845,8 @@ export class LcsDiff {
let
bestScore
=
this
.
_boundaryScore
(
change
.
originalStart
,
change
.
originalLength
,
change
.
modifiedStart
,
change
.
modifiedLength
);
let
bestScore
=
this
.
_boundaryScore
(
change
.
originalStart
,
change
.
originalLength
,
change
.
modifiedStart
,
change
.
modifiedLength
);
for
(
let
delta
=
1
;
;
delta
++
)
{
for
(
let
delta
=
1
;
;
delta
++
)
{
le
t
originalStart
=
change
.
originalStart
-
delta
;
cons
t
originalStart
=
change
.
originalStart
-
delta
;
le
t
modifiedStart
=
change
.
modifiedStart
-
delta
;
cons
t
modifiedStart
=
change
.
modifiedStart
-
delta
;
if
(
originalStart
<
originalStop
||
modifiedStart
<
modifiedStop
)
{
if
(
originalStart
<
originalStop
||
modifiedStart
<
modifiedStop
)
{
break
;
break
;
...
@@ -864,7 +860,7 @@ export class LcsDiff {
...
@@ -864,7 +860,7 @@ export class LcsDiff {
break
;
break
;
}
}
le
t
score
=
this
.
_boundaryScore
(
originalStart
,
change
.
originalLength
,
modifiedStart
,
change
.
modifiedLength
);
cons
t
score
=
this
.
_boundaryScore
(
originalStart
,
change
.
originalLength
,
modifiedStart
,
change
.
modifiedLength
);
if
(
score
>
bestScore
)
{
if
(
score
>
bestScore
)
{
bestScore
=
score
;
bestScore
=
score
;
...
@@ -891,7 +887,7 @@ export class LcsDiff {
...
@@ -891,7 +887,7 @@ export class LcsDiff {
return
true
;
return
true
;
}
}
if
(
originalLength
>
0
)
{
if
(
originalLength
>
0
)
{
le
t
originalEnd
=
originalStart
+
originalLength
;
cons
t
originalEnd
=
originalStart
+
originalLength
;
if
(
this
.
_OriginalIsBoundary
(
originalEnd
-
1
)
||
this
.
_OriginalIsBoundary
(
originalEnd
))
{
if
(
this
.
_OriginalIsBoundary
(
originalEnd
-
1
)
||
this
.
_OriginalIsBoundary
(
originalEnd
))
{
return
true
;
return
true
;
}
}
...
@@ -911,7 +907,7 @@ export class LcsDiff {
...
@@ -911,7 +907,7 @@ export class LcsDiff {
return
true
;
return
true
;
}
}
if
(
modifiedLength
>
0
)
{
if
(
modifiedLength
>
0
)
{
le
t
modifiedEnd
=
modifiedStart
+
modifiedLength
;
cons
t
modifiedEnd
=
modifiedStart
+
modifiedLength
;
if
(
this
.
_ModifiedIsBoundary
(
modifiedEnd
-
1
)
||
this
.
_ModifiedIsBoundary
(
modifiedEnd
))
{
if
(
this
.
_ModifiedIsBoundary
(
modifiedEnd
-
1
)
||
this
.
_ModifiedIsBoundary
(
modifiedEnd
))
{
return
true
;
return
true
;
}
}
...
@@ -920,8 +916,8 @@ export class LcsDiff {
...
@@ -920,8 +916,8 @@ export class LcsDiff {
}
}
private
_boundaryScore
(
originalStart
:
number
,
originalLength
:
number
,
modifiedStart
:
number
,
modifiedLength
:
number
):
number
{
private
_boundaryScore
(
originalStart
:
number
,
originalLength
:
number
,
modifiedStart
:
number
,
modifiedLength
:
number
):
number
{
le
t
originalScore
=
(
this
.
_OriginalRegionIsBoundary
(
originalStart
,
originalLength
)
?
1
:
0
);
cons
t
originalScore
=
(
this
.
_OriginalRegionIsBoundary
(
originalStart
,
originalLength
)
?
1
:
0
);
le
t
modifiedScore
=
(
this
.
_ModifiedRegionIsBoundary
(
modifiedStart
,
modifiedLength
)
?
1
:
0
);
cons
t
modifiedScore
=
(
this
.
_ModifiedRegionIsBoundary
(
modifiedStart
,
modifiedLength
)
?
1
:
0
);
return
(
originalScore
+
modifiedScore
);
return
(
originalScore
+
modifiedScore
);
}
}
...
@@ -942,14 +938,14 @@ export class LcsDiff {
...
@@ -942,14 +938,14 @@ export class LcsDiff {
// might recurse in the middle of a change thereby splitting it into
// might recurse in the middle of a change thereby splitting it into
// two changes. Here in the combining stage, we detect and fuse those
// two changes. Here in the combining stage, we detect and fuse those
// changes back together
// changes back together
le
t
result
=
new
Array
<
DiffChange
>
(
left
.
length
+
right
.
length
-
1
);
cons
t
result
=
new
Array
<
DiffChange
>
(
left
.
length
+
right
.
length
-
1
);
MyArray
.
Copy
(
left
,
0
,
result
,
0
,
left
.
length
-
1
);
MyArray
.
Copy
(
left
,
0
,
result
,
0
,
left
.
length
-
1
);
result
[
left
.
length
-
1
]
=
mergedChangeArr
[
0
];
result
[
left
.
length
-
1
]
=
mergedChangeArr
[
0
];
MyArray
.
Copy
(
right
,
1
,
result
,
left
.
length
,
right
.
length
-
1
);
MyArray
.
Copy
(
right
,
1
,
result
,
left
.
length
,
right
.
length
-
1
);
return
result
;
return
result
;
}
else
{
}
else
{
le
t
result
=
new
Array
<
DiffChange
>
(
left
.
length
+
right
.
length
);
cons
t
result
=
new
Array
<
DiffChange
>
(
left
.
length
+
right
.
length
);
MyArray
.
Copy
(
left
,
0
,
result
,
0
,
left
.
length
);
MyArray
.
Copy
(
left
,
0
,
result
,
0
,
left
.
length
);
MyArray
.
Copy
(
right
,
0
,
result
,
left
.
length
,
right
.
length
);
MyArray
.
Copy
(
right
,
0
,
result
,
left
.
length
,
right
.
length
);
...
@@ -970,9 +966,9 @@ export class LcsDiff {
...
@@ -970,9 +966,9 @@ export class LcsDiff {
Debug
.
Assert
(
left
.
modifiedStart
<=
right
.
modifiedStart
,
'
Left change is not less than or equal to right change
'
);
Debug
.
Assert
(
left
.
modifiedStart
<=
right
.
modifiedStart
,
'
Left change is not less than or equal to right change
'
);
if
(
left
.
originalStart
+
left
.
originalLength
>=
right
.
originalStart
||
left
.
modifiedStart
+
left
.
modifiedLength
>=
right
.
modifiedStart
)
{
if
(
left
.
originalStart
+
left
.
originalLength
>=
right
.
originalStart
||
left
.
modifiedStart
+
left
.
modifiedLength
>=
right
.
modifiedStart
)
{
le
t
originalStart
=
left
.
originalStart
;
cons
t
originalStart
=
left
.
originalStart
;
let
originalLength
=
left
.
originalLength
;
let
originalLength
=
left
.
originalLength
;
le
t
modifiedStart
=
left
.
modifiedStart
;
cons
t
modifiedStart
=
left
.
modifiedStart
;
let
modifiedLength
=
left
.
modifiedLength
;
let
modifiedLength
=
left
.
modifiedLength
;
if
(
left
.
originalStart
+
left
.
originalLength
>=
right
.
originalStart
)
{
if
(
left
.
originalStart
+
left
.
originalLength
>=
right
.
originalStart
)
{
...
@@ -1010,15 +1006,15 @@ export class LcsDiff {
...
@@ -1010,15 +1006,15 @@ export class LcsDiff {
// diagonalsBelow: The number of diagonals below the reference diagonal
// diagonalsBelow: The number of diagonals below the reference diagonal
// diagonalsAbove: The number of diagonals above the reference diagonal
// diagonalsAbove: The number of diagonals above the reference diagonal
le
t
diagonalsBelow
=
diagonalBaseIndex
;
cons
t
diagonalsBelow
=
diagonalBaseIndex
;
le
t
diagonalsAbove
=
numDiagonals
-
diagonalBaseIndex
-
1
;
cons
t
diagonalsAbove
=
numDiagonals
-
diagonalBaseIndex
-
1
;
le
t
diffEven
=
(
numDifferences
%
2
===
0
);
cons
t
diffEven
=
(
numDifferences
%
2
===
0
);
if
(
diagonal
<
0
)
{
if
(
diagonal
<
0
)
{
le
t
lowerBoundEven
=
(
diagonalsBelow
%
2
===
0
);
cons
t
lowerBoundEven
=
(
diagonalsBelow
%
2
===
0
);
return
(
diffEven
===
lowerBoundEven
)
?
0
:
1
;
return
(
diffEven
===
lowerBoundEven
)
?
0
:
1
;
}
else
{
}
else
{
le
t
upperBoundEven
=
(
diagonalsAbove
%
2
===
0
);
cons
t
upperBoundEven
=
(
diagonalsAbove
%
2
===
0
);
return
(
diffEven
===
upperBoundEven
)
?
numDiagonals
-
1
:
numDiagonals
-
2
;
return
(
diffEven
===
upperBoundEven
)
?
numDiagonals
-
1
:
numDiagonals
-
2
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录