Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
dc968531
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,发现更多精彩内容 >>
提交
dc968531
编写于
6月 29, 2015
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3608 from CyrusNajmabadi/sortedIntervalTree
Iterate elements of an interval tree in sorted order.
上级
f1a2bb49
a163c839
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
46 deletion
+83
-46
src/EditorFeatures/Test/Collections/IntervalTreeTests.cs
src/EditorFeatures/Test/Collections/IntervalTreeTests.cs
+64
-38
src/Workspaces/Core/Portable/Shared/Collections/IntervalTree`1.cs
...spaces/Core/Portable/Shared/Collections/IntervalTree`1.cs
+19
-8
未找到文件。
src/EditorFeatures/Test/Collections/IntervalTreeTests.cs
浏览文件 @
dc968531
...
...
@@ -153,44 +153,6 @@ public void TestOverlappingStart()
}
}
[
Fact
]
public
void
TestRightRotation
()
{
var
nodes
=
new
[]
{
Tuple
.
Create
(
8
,
1
,
"a"
),
Tuple
.
Create
(
10
,
1
,
"b"
),
Tuple
.
Create
(
4
,
1
,
"c"
),
Tuple
.
Create
(
6
,
1
,
"d"
),
Tuple
.
Create
(
0
,
1
,
"e"
),
Tuple
.
Create
(
2
,
1
,
"f"
)
};
foreach
(
var
tree
in
CreateTrees
(
nodes
))
{
Assert
.
True
(
tree
.
Select
(
t
=>
t
.
Item3
).
SequenceEqual
(
List
(
"c"
,
"e"
,
"f"
,
"a"
,
"d"
,
"b"
)));
}
}
[
Fact
]
public
void
InnerLeftOuterRightRotation
()
{
var
nodes
=
new
[]
{
Tuple
.
Create
(
8
,
1
,
"a"
),
Tuple
.
Create
(
10
,
1
,
"b"
),
Tuple
.
Create
(
2
,
1
,
"c"
),
Tuple
.
Create
(
0
,
1
,
"e"
),
Tuple
.
Create
(
4
,
1
,
"d"
),
Tuple
.
Create
(
6
,
1
,
"f"
)
};
foreach
(
var
tree
in
CreateTrees
(
nodes
))
{
Assert
.
True
(
tree
.
Select
(
t
=>
t
.
Item3
).
SequenceEqual
(
List
(
"d"
,
"c"
,
"e"
,
"a"
,
"f"
,
"b"
)));
}
}
[
Fact
]
public
void
TestOverlappingEnd
()
{
...
...
@@ -307,6 +269,70 @@ public void TestEmptySpanAtStart()
Assert
.
Equal
(
1
,
tree
.
Count
());
}
private
class
Int32Introspector
:
IIntervalIntrospector
<
int
>
{
public
static
Int32Introspector
Instance
=
new
Int32Introspector
();
public
int
GetLength
(
int
value
)
{
return
0
;
}
public
int
GetStart
(
int
value
)
{
return
value
;
}
}
private
IntervalTree
<
int
>
CreateIntTree
(
params
int
[]
values
)
{
return
new
IntervalTree
<
int
>(
Int32Introspector
.
Instance
,
values
);
}
[
Fact
]
public
void
TestSortedEnumerable1
()
{
var
tree
=
new
IntervalTree
<
int
>(
Int32Introspector
.
Instance
,
new
[]
{
0
,
0
,
0
});
Assert
.
Equal
(
CreateIntTree
(
0
,
0
,
0
),
new
[]
{
0
,
0
,
0
});
Assert
.
Equal
(
CreateIntTree
(
0
,
0
,
1
),
new
[]
{
0
,
0
,
1
});
Assert
.
Equal
(
CreateIntTree
(
0
,
0
,
2
),
new
[]
{
0
,
0
,
2
});
Assert
.
Equal
(
CreateIntTree
(
0
,
1
,
0
),
new
[]
{
0
,
0
,
1
});
Assert
.
Equal
(
CreateIntTree
(
0
,
1
,
1
),
new
[]
{
0
,
1
,
1
});
Assert
.
Equal
(
CreateIntTree
(
0
,
1
,
2
),
new
[]
{
0
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
0
,
2
,
0
),
new
[]
{
0
,
0
,
2
});
Assert
.
Equal
(
CreateIntTree
(
0
,
2
,
1
),
new
[]
{
0
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
0
,
2
,
2
),
new
[]
{
0
,
2
,
2
});
Assert
.
Equal
(
CreateIntTree
(
1
,
0
,
0
),
new
[]
{
0
,
0
,
1
});
Assert
.
Equal
(
CreateIntTree
(
1
,
0
,
1
),
new
[]
{
0
,
1
,
1
});
Assert
.
Equal
(
CreateIntTree
(
1
,
0
,
2
),
new
[]
{
0
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
1
,
1
,
0
),
new
[]
{
0
,
1
,
1
});
Assert
.
Equal
(
CreateIntTree
(
1
,
1
,
1
),
new
[]
{
1
,
1
,
1
});
Assert
.
Equal
(
CreateIntTree
(
1
,
1
,
2
),
new
[]
{
1
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
1
,
2
,
0
),
new
[]
{
0
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
1
,
2
,
1
),
new
[]
{
1
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
1
,
2
,
2
),
new
[]
{
1
,
2
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
0
,
0
),
new
[]
{
0
,
0
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
0
,
1
),
new
[]
{
0
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
0
,
2
),
new
[]
{
0
,
2
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
1
,
0
),
new
[]
{
0
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
1
,
1
),
new
[]
{
1
,
1
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
1
,
2
),
new
[]
{
1
,
2
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
2
,
0
),
new
[]
{
0
,
2
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
2
,
1
),
new
[]
{
1
,
2
,
2
});
Assert
.
Equal
(
CreateIntTree
(
2
,
2
,
2
),
new
[]
{
2
,
2
,
2
});
}
[
Fact
]
public
void
TestSortedEnumerable2
()
{
var
tree
=
new
IntervalTree
<
int
>(
Int32Introspector
.
Instance
,
new
[]
{
1
,
0
});
Assert
.
Equal
(
tree
,
new
[]
{
0
,
1
});
}
private
static
void
TestOverlapsAndIntersects
(
IList
<
Tuple
<
int
,
int
,
string
>>
spans
)
{
foreach
(
var
tree
in
CreateTrees
(
spans
))
...
...
src/Workspaces/Core/Portable/Shared/Collections/IntervalTree`1.cs
浏览文件 @
dc968531
...
...
@@ -309,17 +309,28 @@ public IEnumerator<T> GetEnumerator()
yield
break
;
}
var
candidates
=
new
Stack
<
Node
>();
candidates
.
Push
(
root
);
// The bool indicates if this is the first time we are seeing the node.
var
candidates
=
new
Stack
<
ValueTuple
<
Node
,
bool
>>();
candidates
.
Push
(
ValueTuple
.
Create
(
root
,
true
));
while
(
candidates
.
Count
!=
0
)
{
var
current
=
candidates
.
Pop
();
if
(
current
!=
null
)
var
currentTuple
=
candidates
.
Pop
();
var
currentNode
=
currentTuple
.
Item1
;
if
(
currentNode
!=
null
)
{
candidates
.
Push
(
current
.
Right
);
candidates
.
Push
(
current
.
Left
);
yield
return
current
.
Value
;
if
(
currentTuple
.
Item2
)
{
// First time seeing this node. Mark that we've been seen and recurse
// down the left side. The next time we see this node we'll yield it
// out.
candidates
.
Push
(
ValueTuple
.
Create
(
currentNode
.
Right
,
true
));
candidates
.
Push
(
ValueTuple
.
Create
(
currentNode
,
false
));
candidates
.
Push
(
ValueTuple
.
Create
(
currentNode
.
Left
,
true
));
}
else
{
yield
return
currentNode
.
Value
;
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录