Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f60103dc
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,发现更多精彩内容 >>
提交
f60103dc
编写于
5月 01, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
https://github.com/microsoft/vscode/issues/96691
上级
2bac4776
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
41 deletion
+33
-41
src/vs/platform/instantiation/common/graph.ts
src/vs/platform/instantiation/common/graph.ts
+32
-40
src/vs/platform/instantiation/test/common/graph.test.ts
src/vs/platform/instantiation/test/common/graph.test.ts
+1
-1
未找到文件。
src/vs/platform/instantiation/common/graph.ts
浏览文件 @
f60103dc
...
...
@@ -3,86 +3,78 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
isEmptyObject
}
from
'
vs/base/common/types
'
;
import
{
forEach
}
from
'
vs/base/common/collections
'
;
export
class
Node
<
T
>
{
export
interface
Node
<
T
>
{
data
:
T
;
incoming
:
{
[
key
:
string
]:
Node
<
T
>
};
outgoing
:
{
[
key
:
string
]:
Node
<
T
>
};
}
readonly
data
:
T
;
readonly
incoming
=
new
Map
<
string
,
Node
<
T
>>
();
readonly
outgoing
=
new
Map
<
string
,
Node
<
T
>>
();
function
newNode
<
T
>
(
data
:
T
):
Node
<
T
>
{
return
{
data
:
data
,
incoming
:
Object
.
create
(
null
),
outgoing
:
Object
.
create
(
null
)
};
constructor
(
data
:
T
)
{
this
.
data
=
data
;
}
}
export
class
Graph
<
T
>
{
private
_nodes
:
{
[
key
:
string
]:
Node
<
T
>
}
=
Object
.
create
(
null
);
private
readonly
_nodes
=
new
Map
<
string
,
Node
<
T
>>
(
);
constructor
(
private
_hashFn
:
(
element
:
T
)
=>
string
)
{
constructor
(
private
readonly
_hashFn
:
(
element
:
T
)
=>
string
)
{
// empty
}
roots
():
Node
<
T
>
[]
{
const
ret
:
Node
<
T
>
[]
=
[];
for
Each
(
this
.
_nodes
,
entry
=>
{
if
(
isEmptyObject
(
entry
.
value
.
outgoing
)
)
{
ret
.
push
(
entry
.
valu
e
);
for
(
let
node
of
this
.
_nodes
.
values
())
{
if
(
node
.
outgoing
.
size
===
0
)
{
ret
.
push
(
nod
e
);
}
}
);
}
return
ret
;
}
insertEdge
(
from
:
T
,
to
:
T
):
void
{
const
fromNode
=
this
.
lookupOrInsertNode
(
from
)
,
toNode
=
this
.
lookupOrInsertNode
(
to
);
const
fromNode
=
this
.
lookupOrInsertNode
(
from
)
;
const
toNode
=
this
.
lookupOrInsertNode
(
to
);
fromNode
.
outgoing
[
this
.
_hashFn
(
to
)]
=
toNode
;
toNode
.
incoming
[
this
.
_hashFn
(
from
)]
=
fromNode
;
fromNode
.
outgoing
.
set
(
this
.
_hashFn
(
to
),
toNode
)
;
toNode
.
incoming
.
set
(
this
.
_hashFn
(
from
),
fromNode
)
;
}
removeNode
(
data
:
T
):
void
{
const
key
=
this
.
_hashFn
(
data
);
delete
this
.
_nodes
[
key
]
;
for
Each
(
this
.
_nodes
,
(
entry
)
=>
{
delete
entry
.
value
.
outgoing
[
key
]
;
delete
entry
.
value
.
incoming
[
key
]
;
}
);
this
.
_nodes
.
delete
(
key
)
;
for
(
let
node
of
this
.
_nodes
.
values
())
{
node
.
outgoing
.
delete
(
key
)
;
node
.
incoming
.
delete
(
key
)
;
}
}
lookupOrInsertNode
(
data
:
T
):
Node
<
T
>
{
const
key
=
this
.
_hashFn
(
data
);
let
node
=
this
.
_nodes
[
key
]
;
let
node
=
this
.
_nodes
.
get
(
key
)
;
if
(
!
node
)
{
node
=
newNode
(
data
);
this
.
_nodes
[
key
]
=
node
;
node
=
new
Node
(
data
);
this
.
_nodes
.
set
(
key
,
node
)
;
}
return
node
;
}
lookup
(
data
:
T
):
Node
<
T
>
{
return
this
.
_nodes
[
this
.
_hashFn
(
data
)]
;
lookup
(
data
:
T
):
Node
<
T
>
|
undefined
{
return
this
.
_nodes
.
get
(
this
.
_hashFn
(
data
))
;
}
isEmpty
():
boolean
{
for
(
const
_key
in
this
.
_nodes
)
{
return
false
;
}
return
true
;
return
this
.
_nodes
.
size
===
0
;
}
toString
():
string
{
let
data
:
string
[]
=
[];
forEach
(
this
.
_nodes
,
entry
=>
{
data
.
push
(
`
${
entry
.
key
}
, (incoming)[
${
Object
.
keys
(
entry
.
value
.
incoming
).
join
(
'
,
'
)}
], (outgoing)[
${
Object
.
keys
(
entry
.
value
.
outgoing
).
join
(
'
,
'
)}
]`
);
});
for
(
let
[
key
,
value
]
of
this
.
_nodes
)
{
data
.
push
(
`
${
key
}
, (incoming)[
${[...
value
.
incoming
.
keys
()].
join
(
'
,
'
)}
], (outgoing)[
${[...
value
.
outgoing
.
keys
()].
join
(
'
,
'
)}
]`
);
}
return
data
.
join
(
'
\n
'
);
}
}
src/vs/platform/instantiation/test/common/graph.test.ts
浏览文件 @
f60103dc
...
...
@@ -19,7 +19,7 @@ suite('Graph', () => {
test
(
'
inserts nodes when not there yet
'
,
function
()
{
assert
.
deepEqual
(
graph
.
lookup
(
'
ddd
'
),
null
);
assert
.
deepEqual
(
graph
.
lookupOrInsertNode
(
'
ddd
'
).
data
,
'
ddd
'
);
assert
.
deepEqual
(
graph
.
lookup
(
'
ddd
'
).
data
,
'
ddd
'
);
assert
.
deepEqual
(
graph
.
lookup
(
'
ddd
'
)
!
.
data
,
'
ddd
'
);
});
test
(
'
can remove nodes and get length
'
,
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录