Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3026acf9
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,发现更多精彩内容 >>
提交
3026acf9
编写于
6月 30, 2015
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make interval tree construction always 'in-place'
上级
14a02817
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
99 deletion
+40
-99
src/Workspaces/Core/Portable/Formatting/ContextIntervalTree.cs
...orkspaces/Core/Portable/Formatting/ContextIntervalTree.cs
+1
-1
src/Workspaces/Core/Portable/Shared/Collections/IntervalTree`1.Node.cs
...s/Core/Portable/Shared/Collections/IntervalTree`1.Node.cs
+24
-75
src/Workspaces/Core/Portable/Shared/Collections/IntervalTree`1.cs
...spaces/Core/Portable/Shared/Collections/IntervalTree`1.cs
+14
-22
src/Workspaces/Core/Portable/Shared/Collections/SimpleIntervalTree`1.cs
.../Core/Portable/Shared/Collections/SimpleIntervalTree`1.cs
+1
-1
未找到文件。
src/Workspaces/Core/Portable/Formatting/ContextIntervalTree.cs
浏览文件 @
3026acf9
...
@@ -32,7 +32,7 @@ public ContextIntervalTree(IIntervalIntrospector<T> introspector)
...
@@ -32,7 +32,7 @@ public ContextIntervalTree(IIntervalIntrospector<T> introspector)
public
void
AddIntervalInPlace
(
T
value
)
public
void
AddIntervalInPlace
(
T
value
)
{
{
var
newNode
=
new
Node
(
Introspector
,
value
);
var
newNode
=
new
Node
(
Introspector
,
value
);
this
.
root
=
Insert
(
root
,
newNode
,
Introspector
,
inPlace
:
true
);
this
.
root
=
Insert
(
root
,
newNode
,
Introspector
);
}
}
public
T
GetSmallestEdgeExclusivelyContainingInterval
(
int
start
,
int
length
)
public
T
GetSmallestEdgeExclusivelyContainingInterval
(
int
start
,
int
length
)
...
...
src/Workspaces/Core/Portable/Shared/Collections/IntervalTree`1.Node.cs
浏览文件 @
3026acf9
...
@@ -61,11 +61,6 @@ internal void SetLeftRight(Node left, Node right, IIntervalIntrospector<T> intro
...
@@ -61,11 +61,6 @@ internal void SetLeftRight(Node left, Node right, IIntervalIntrospector<T> intro
}
}
}
}
internal
Node
With
(
Node
left
,
Node
right
,
IIntervalIntrospector
<
T
>
introspector
)
{
return
new
Node
(
introspector
,
this
.
Value
,
left
,
right
);
}
// Sample:
// Sample:
// 1 2
// 1 2
// / \ / \
// / \ / \
...
@@ -74,25 +69,13 @@ internal Node With(Node left, Node right, IIntervalIntrospector<T> introspector)
...
@@ -74,25 +69,13 @@ internal Node With(Node left, Node right, IIntervalIntrospector<T> introspector)
// 3 c a b c d
// 3 c a b c d
// / \
// / \
// a b
// a b
internal
Node
RightRotation
(
bool
inPlace
,
IIntervalIntrospector
<
T
>
introspector
)
internal
Node
RightRotation
(
IIntervalIntrospector
<
T
>
introspector
)
{
{
if
(
inPlace
)
var
oldLeft
=
this
.
Left
;
{
this
.
SetLeftRight
(
this
.
Left
.
Right
,
this
.
Right
,
introspector
);
var
oldLeft
=
this
.
Left
;
oldLeft
.
SetLeftRight
(
oldLeft
.
Left
,
this
,
introspector
);
this
.
SetLeftRight
(
this
.
Left
.
Right
,
this
.
Right
,
introspector
);
oldLeft
.
SetLeftRight
(
oldLeft
.
Left
,
this
,
introspector
);
return
oldLeft
;
return
oldLeft
;
}
else
{
var
newLeft
=
this
.
Left
.
Left
;
var
newRight
=
this
.
With
(
this
.
Left
.
Right
,
this
.
Right
,
introspector
);
return
this
.
Left
.
With
(
newLeft
,
newRight
,
introspector
);
}
}
}
// Sample:
// Sample:
...
@@ -103,24 +86,12 @@ internal Node RightRotation(bool inPlace, IIntervalIntrospector<T> introspector)
...
@@ -103,24 +86,12 @@ internal Node RightRotation(bool inPlace, IIntervalIntrospector<T> introspector)
// b 3 a b c d
// b 3 a b c d
// / \
// / \
// c d
// c d
internal
Node
LeftRotation
(
bool
inPlace
,
IIntervalIntrospector
<
T
>
introspector
)
internal
Node
LeftRotation
(
IIntervalIntrospector
<
T
>
introspector
)
{
{
if
(
inPlace
)
var
oldRight
=
this
.
Right
;
{
this
.
SetLeftRight
(
this
.
Left
,
this
.
Right
.
Left
,
introspector
);
var
oldRight
=
this
.
Right
;
oldRight
.
SetLeftRight
(
this
,
oldRight
.
Right
,
introspector
);
this
.
SetLeftRight
(
this
.
Left
,
this
.
Right
.
Left
,
introspector
);
return
oldRight
;
oldRight
.
SetLeftRight
(
this
,
oldRight
.
Right
,
introspector
);
return
oldRight
;
}
else
{
var
newLeft
=
this
.
With
(
this
.
Left
,
this
.
Right
.
Left
,
introspector
);
var
newRight
=
this
.
Right
.
Right
;
return
this
.
Right
.
With
(
newLeft
,
newRight
,
introspector
);
}
}
}
// Sample:
// Sample:
...
@@ -131,27 +102,16 @@ internal Node LeftRotation(bool inPlace, IIntervalIntrospector<T> introspector)
...
@@ -131,27 +102,16 @@ internal Node LeftRotation(bool inPlace, IIntervalIntrospector<T> introspector)
// 3 d b 2 a b c d
// 3 d b 2 a b c d
// / \ / \
// / \ / \
// b c c d
// b c c d
internal
Node
InnerRightOuterLeftRotation
(
bool
inPlace
,
IIntervalIntrospector
<
T
>
introspector
)
internal
Node
InnerRightOuterLeftRotation
(
IIntervalIntrospector
<
T
>
introspector
)
{
{
if
(
inPlace
)
var
newTop
=
this
.
Right
.
Left
;
{
var
oldRight
=
this
.
Right
;
var
newTop
=
this
.
Right
.
Left
;
var
oldRight
=
this
.
Right
;
this
.
SetLeftRight
(
this
.
Left
,
this
.
Right
.
Left
.
Left
,
introspector
);
this
.
SetLeftRight
(
this
.
Left
,
this
.
Right
.
Left
.
Left
,
introspector
);
oldRight
.
SetLeftRight
(
oldRight
.
Left
.
Right
,
oldRight
.
Right
,
introspector
);
oldRight
.
SetLeftRight
(
oldRight
.
Left
.
Right
,
oldRight
.
Right
,
introspector
);
newTop
.
SetLeftRight
(
this
,
oldRight
,
introspector
);
newTop
.
SetLeftRight
(
this
,
oldRight
,
introspector
);
return
newTop
;
return
newTop
;
}
else
{
var
temp
=
this
.
With
(
this
.
Left
,
this
.
Right
.
RightRotation
(
inPlace
,
introspector
),
introspector
);
return
temp
.
LeftRotation
(
inPlace
,
introspector
);
}
}
}
// Sample:
// Sample:
...
@@ -162,27 +122,16 @@ internal Node InnerRightOuterLeftRotation(bool inPlace, IIntervalIntrospector<T>
...
@@ -162,27 +122,16 @@ internal Node InnerRightOuterLeftRotation(bool inPlace, IIntervalIntrospector<T>
// a 3 2 c a b c d
// a 3 2 c a b c d
// / \ / \
// / \ / \
// b c a b
// b c a b
internal
Node
InnerLeftOuterRightRotation
(
bool
inPlace
,
IIntervalIntrospector
<
T
>
introspector
)
internal
Node
InnerLeftOuterRightRotation
(
IIntervalIntrospector
<
T
>
introspector
)
{
{
if
(
inPlace
)
var
newTop
=
this
.
Left
.
Right
;
{
var
oldLeft
=
this
.
Left
;
var
newTop
=
this
.
Left
.
Right
;
var
oldLeft
=
this
.
Left
;
this
.
SetLeftRight
(
this
.
Left
.
Right
.
Right
,
this
.
Right
,
introspector
);
this
.
SetLeftRight
(
this
.
Left
.
Right
.
Right
,
this
.
Right
,
introspector
);
oldLeft
.
SetLeftRight
(
oldLeft
.
Left
,
oldLeft
.
Right
.
Left
,
introspector
);
oldLeft
.
SetLeftRight
(
oldLeft
.
Left
,
oldLeft
.
Right
.
Left
,
introspector
);
newTop
.
SetLeftRight
(
oldLeft
,
this
,
introspector
);
newTop
.
SetLeftRight
(
oldLeft
,
this
,
introspector
);
return
newTop
;
return
newTop
;
}
else
{
var
temp
=
this
.
With
(
this
.
Left
.
LeftRotation
(
inPlace
,
introspector
),
this
.
Right
,
introspector
);
return
temp
.
RightRotation
(
inPlace
,
introspector
);
}
}
}
}
}
}
}
...
...
src/Workspaces/Core/Portable/Shared/Collections/IntervalTree`1.cs
浏览文件 @
3026acf9
...
@@ -38,7 +38,7 @@ public IntervalTree(IIntervalIntrospector<T> introspector, IEnumerable<T> values
...
@@ -38,7 +38,7 @@ public IntervalTree(IIntervalIntrospector<T> introspector, IEnumerable<T> values
{
{
foreach
(
var
value
in
values
)
foreach
(
var
value
in
values
)
{
{
root
=
Insert
(
root
,
new
Node
(
introspector
,
value
),
introspector
,
inPlace
:
true
);
root
=
Insert
(
root
,
new
Node
(
introspector
,
value
),
introspector
);
}
}
}
}
...
@@ -223,13 +223,13 @@ public bool IsEmpty()
...
@@ -223,13 +223,13 @@ public bool IsEmpty()
return
this
.
root
==
null
;
return
this
.
root
==
null
;
}
}
protected
static
Node
Insert
(
Node
root
,
Node
newNode
,
IIntervalIntrospector
<
T
>
introspector
,
bool
inPlace
)
protected
static
Node
Insert
(
Node
root
,
Node
newNode
,
IIntervalIntrospector
<
T
>
introspector
)
{
{
var
newNodeStart
=
introspector
.
GetStart
(
newNode
.
Value
);
var
newNodeStart
=
introspector
.
GetStart
(
newNode
.
Value
);
return
Insert
(
root
,
newNode
,
newNodeStart
,
introspector
,
inPlace
);
return
Insert
(
root
,
newNode
,
newNodeStart
,
introspector
);
}
}
private
static
Node
Insert
(
Node
root
,
Node
newNode
,
int
newNodeStart
,
IIntervalIntrospector
<
T
>
introspector
,
bool
inPlace
)
private
static
Node
Insert
(
Node
root
,
Node
newNode
,
int
newNodeStart
,
IIntervalIntrospector
<
T
>
introspector
)
{
{
if
(
root
==
null
)
if
(
root
==
null
)
{
{
...
@@ -240,30 +240,22 @@ private static Node Insert(Node root, Node newNode, int newNodeStart, IIntervalI
...
@@ -240,30 +240,22 @@ private static Node Insert(Node root, Node newNode, int newNodeStart, IIntervalI
if
(
newNodeStart
<
introspector
.
GetStart
(
root
.
Value
))
if
(
newNodeStart
<
introspector
.
GetStart
(
root
.
Value
))
{
{
newLeft
=
Insert
(
root
.
Left
,
newNode
,
newNodeStart
,
introspector
,
inPlace
);
newLeft
=
Insert
(
root
.
Left
,
newNode
,
newNodeStart
,
introspector
);
newRight
=
root
.
Right
;
newRight
=
root
.
Right
;
}
}
else
else
{
{
newLeft
=
root
.
Left
;
newLeft
=
root
.
Left
;
newRight
=
Insert
(
root
.
Right
,
newNode
,
newNodeStart
,
introspector
,
inPlace
);
newRight
=
Insert
(
root
.
Right
,
newNode
,
newNodeStart
,
introspector
);
}
}
Node
newRoot
;
root
.
SetLeftRight
(
newLeft
,
newRight
,
introspector
);
if
(
inPlace
)
var
newRoot
=
root
;
{
root
.
SetLeftRight
(
newLeft
,
newRight
,
introspector
);
newRoot
=
root
;
}
else
{
newRoot
=
new
Node
(
introspector
,
root
.
Value
,
newLeft
,
newRight
);
}
return
Balance
(
newRoot
,
in
Place
,
in
trospector
);
return
Balance
(
newRoot
,
introspector
);
}
}
private
static
Node
Balance
(
Node
node
,
bool
inPlace
,
IIntervalIntrospector
<
T
>
introspector
)
private
static
Node
Balance
(
Node
node
,
IIntervalIntrospector
<
T
>
introspector
)
{
{
int
balanceFactor
=
BalanceFactor
(
node
);
int
balanceFactor
=
BalanceFactor
(
node
);
if
(
balanceFactor
==
-
2
)
if
(
balanceFactor
==
-
2
)
...
@@ -271,12 +263,12 @@ private static Node Balance(Node node, bool inPlace, IIntervalIntrospector<T> in
...
@@ -271,12 +263,12 @@ private static Node Balance(Node node, bool inPlace, IIntervalIntrospector<T> in
int
rightBalance
=
BalanceFactor
(
node
.
Right
);
int
rightBalance
=
BalanceFactor
(
node
.
Right
);
if
(
rightBalance
==
-
1
)
if
(
rightBalance
==
-
1
)
{
{
return
node
.
LeftRotation
(
in
Place
,
in
trospector
);
return
node
.
LeftRotation
(
introspector
);
}
}
else
else
{
{
Contract
.
Requires
(
rightBalance
==
1
);
Contract
.
Requires
(
rightBalance
==
1
);
return
node
.
InnerRightOuterLeftRotation
(
in
Place
,
in
trospector
);
return
node
.
InnerRightOuterLeftRotation
(
introspector
);
}
}
}
}
else
if
(
balanceFactor
==
2
)
else
if
(
balanceFactor
==
2
)
...
@@ -284,12 +276,12 @@ private static Node Balance(Node node, bool inPlace, IIntervalIntrospector<T> in
...
@@ -284,12 +276,12 @@ private static Node Balance(Node node, bool inPlace, IIntervalIntrospector<T> in
int
leftBalance
=
BalanceFactor
(
node
.
Left
);
int
leftBalance
=
BalanceFactor
(
node
.
Left
);
if
(
leftBalance
==
1
)
if
(
leftBalance
==
1
)
{
{
return
node
.
RightRotation
(
in
Place
,
in
trospector
);
return
node
.
RightRotation
(
introspector
);
}
}
else
else
{
{
Contract
.
Requires
(
leftBalance
==
-
1
);
Contract
.
Requires
(
leftBalance
==
-
1
);
return
node
.
InnerLeftOuterRightRotation
(
in
Place
,
in
trospector
);
return
node
.
InnerLeftOuterRightRotation
(
introspector
);
}
}
}
}
...
...
src/Workspaces/Core/Portable/Shared/Collections/SimpleIntervalTree`1.cs
浏览文件 @
3026acf9
...
@@ -32,7 +32,7 @@ public SimpleIntervalTree(IIntervalIntrospector<T> introspector, IEnumerable<T>
...
@@ -32,7 +32,7 @@ public SimpleIntervalTree(IIntervalIntrospector<T> introspector, IEnumerable<T>
{
{
foreach
(
var
value
in
values
)
foreach
(
var
value
in
values
)
{
{
root
=
Insert
(
root
,
new
Node
(
introspector
,
value
),
introspector
,
inPlace
:
true
);
root
=
Insert
(
root
,
new
Node
(
introspector
,
value
),
introspector
);
}
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录