Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b72cd621
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b72cd621
编写于
10月 07, 2015
作者:
T
Tomas Matousek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle known-matches collisions
上级
c816547a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
15 deletion
+74
-15
src/Workspaces/Core/Portable/Differencing/Match.cs
src/Workspaces/Core/Portable/Differencing/Match.cs
+21
-15
src/Workspaces/CoreTest/Differencing/MatchTests.cs
src/Workspaces/CoreTest/Differencing/MatchTests.cs
+53
-0
未找到文件。
src/Workspaces/Core/Portable/Differencing/Match.cs
浏览文件 @
b72cd621
...
...
@@ -31,9 +31,7 @@ internal Match(TNode root1, TNode root2, TreeComparer<TNode> comparer, IEnumerab
_root1
=
root1
;
_root2
=
root2
;
_comparer
=
comparer
;
_oneToTwo
=
new
Dictionary
<
TNode
,
TNode
>();
_twoToOne
=
new
Dictionary
<
TNode
,
TNode
>();
int
labelCount
=
comparer
.
LabelCount
;
// Calculate chains (not including root node):
...
...
@@ -42,6 +40,12 @@ internal Match(TNode root1, TNode root2, TreeComparer<TNode> comparer, IEnumerab
CategorizeNodesByLabels
(
comparer
,
root1
,
labelCount
,
out
nodes1
,
out
count1
);
CategorizeNodesByLabels
(
comparer
,
root2
,
labelCount
,
out
nodes2
,
out
count2
);
_oneToTwo
=
new
Dictionary
<
TNode
,
TNode
>();
_twoToOne
=
new
Dictionary
<
TNode
,
TNode
>();
// Root nodes always match. Add them before adding known matches to make sure we always have root mapping.
TryAdd
(
root1
,
root2
);
if
(
knownMatches
!=
null
)
{
foreach
(
var
knownMatch
in
knownMatches
)
...
...
@@ -61,10 +65,8 @@ internal Match(TNode root1, TNode root2, TreeComparer<TNode> comparer, IEnumerab
throw
new
ArgumentException
(
string
.
Format
(
WorkspacesResources
.
NodeMustBeContainedInTheNewTree
,
knownMatch
.
Value
),
nameof
(
knownMatches
));
}
if
(!
_oneToTwo
.
ContainsKey
(
knownMatch
.
Key
))
{
Add
(
knownMatch
.
Key
,
knownMatch
.
Value
);
}
// skip pairs whose key or value is already mapped:
TryAdd
(
knownMatch
.
Key
,
knownMatch
.
Value
);
}
}
...
...
@@ -111,12 +113,6 @@ private void ComputeMatch(List<TNode>[] nodes1, List<TNode>[] nodes2)
{
Debug
.
Assert
(
nodes1
.
Length
==
nodes2
.
Length
);
// Root nodes always match but they might have been added as knownMatches
if
(!
HasPartnerInTree2
(
_root1
))
{
Add
(
_root1
,
_root2
);
}
// --- The original FastMatch algorithm ---
//
// For each leaf label l, and then for each internal node label l do:
...
...
@@ -257,7 +253,11 @@ private void ComputeMatchForLabel(List<TNode> s1, List<TNode> s2, int tiedToAnce
if
(
matched
&&
bestDistance
<=
maxAcceptableDistance
)
{
Add
(
node1
,
bestMatch
);
bool
added
=
TryAdd
(
node1
,
bestMatch
);
// We checked above that node1 doesn't have a partner.
// The map is a bijection by construction, so we should be able to add the mapping.
Debug
.
Assert
(
added
);
// If we exactly matched to firstNonMatch2 we can advance it.
if
(
i2
==
firstNonMatch2
)
...
...
@@ -268,13 +268,19 @@ private void ComputeMatchForLabel(List<TNode> s1, List<TNode> s2, int tiedToAnce
}
}
internal
void
Add
(
TNode
node1
,
TNode
node2
)
internal
bool
Try
Add
(
TNode
node1
,
TNode
node2
)
{
Debug
.
Assert
(
_comparer
.
TreesEqual
(
node1
,
_root1
));
Debug
.
Assert
(
_comparer
.
TreesEqual
(
node2
,
_root2
));
if
(
_oneToTwo
.
ContainsKey
(
node1
)
||
_twoToOne
.
ContainsKey
(
node2
))
{
return
false
;
}
_oneToTwo
.
Add
(
node1
,
node2
);
_twoToOne
.
Add
(
node2
,
node1
);
return
true
;
}
internal
bool
TryGetPartnerInTree1
(
TNode
node2
,
out
TNode
partner1
)
...
...
src/Workspaces/CoreTest/Differencing/MatchTests.cs
浏览文件 @
b72cd621
...
...
@@ -30,5 +30,58 @@ public void KnownMatches()
Assert
.
Throws
<
ArgumentException
>(()
=>
TestTreeComparer
.
Instance
.
ComputeMatch
(
oldRoot
,
newRoot
,
new
[]
{
KeyValuePair
.
Create
(
x1
,
x2
),
KeyValuePair
.
Create
(
x1
,
new
TestNode
(
0
,
0
))
}));
}
[
Fact
]
public
void
KnownMatchesDups
()
{
TestNode
x1
,
x2
,
y1
,
y2
,
n
;
var
oldRoot
=
new
TestNode
(
0
,
1
,
x1
=
new
TestNode
(
1
,
1
),
y1
=
new
TestNode
(
1
,
4
));
var
newRoot
=
new
TestNode
(
0
,
1
,
x2
=
new
TestNode
(
1
,
2
),
y2
=
new
TestNode
(
1
,
3
));
var
m
=
TestTreeComparer
.
Instance
.
ComputeMatch
(
oldRoot
,
newRoot
,
new
[]
{
KeyValuePair
.
Create
(
x1
,
x2
),
KeyValuePair
.
Create
(
y1
,
x2
),
});
// the first one wins:
Assert
.
True
(
m
.
TryGetNewNode
(
x1
,
out
n
));
Assert
.
Equal
(
x2
,
n
);
Assert
.
True
(
m
.
TryGetOldNode
(
x2
,
out
n
));
Assert
.
Equal
(
x1
,
n
);
Assert
.
True
(
m
.
TryGetNewNode
(
y1
,
out
n
));
// matched
Assert
.
Equal
(
y2
,
n
);
}
[
Fact
]
public
void
KnownMatchesRootMatch
()
{
TestNode
x1
,
x2
,
n
;
var
oldRoot
=
new
TestNode
(
0
,
1
,
x1
=
new
TestNode
(
0
,
1
));
var
newRoot
=
new
TestNode
(
0
,
1
,
x2
=
new
TestNode
(
0
,
2
));
var
m
=
TestTreeComparer
.
Instance
.
ComputeMatch
(
oldRoot
,
newRoot
,
new
[]
{
KeyValuePair
.
Create
(
x1
,
newRoot
),
});
// the root wins:
Assert
.
True
(
m
.
TryGetNewNode
(
x1
,
out
n
));
// matched
Assert
.
Equal
(
x2
,
n
);
Assert
.
True
(
m
.
TryGetOldNode
(
newRoot
,
out
n
));
Assert
.
Equal
(
oldRoot
,
n
);
Assert
.
True
(
m
.
TryGetNewNode
(
oldRoot
,
out
n
));
Assert
.
Equal
(
newRoot
,
n
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录