Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
cf9337d2
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,发现更多精彩内容 >>
提交
cf9337d2
编写于
4月 15, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
💄
graph updates
上级
13c79c8c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
30 deletion
+30
-30
src/vs/base/common/graph.ts
src/vs/base/common/graph.ts
+30
-30
未找到文件。
src/vs/base/common/graph.ts
浏览文件 @
cf9337d2
...
...
@@ -4,82 +4,82 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
objects
=
require
(
'
vs/base/common/types
'
)
;
import
collections
=
require
(
'
vs/base/common/collections
'
)
;
import
{
isEmptyObject
}
from
'
vs/base/common/types
'
;
import
{
forEach
,
contains
,
lookup
}
from
'
vs/base/common/collections
'
;
export
interface
Node
<
T
>
{
data
:
T
;
incoming
:
{[
key
:
string
]:
Node
<
T
>
};
outgoing
:
{[
key
:
string
]:
Node
<
T
>
};
data
:
T
;
incoming
:
{
[
key
:
string
]:
Node
<
T
>
};
outgoing
:
{
[
key
:
string
]:
Node
<
T
>
};
}
export
function
newNode
<
T
>
(
data
:
T
):
Node
<
T
>
{
function
newNode
<
T
>
(
data
:
T
):
Node
<
T
>
{
return
{
data
:
data
,
incoming
:
{},
data
:
data
,
incoming
:
{},
outgoing
:
{}
};
}
export
class
Graph
<
T
>
{
private
_nodes
:
{[
key
:
string
]:
Node
<
T
>
}
=
Object
.
create
(
null
);
private
_nodes
:
{
[
key
:
string
]:
Node
<
T
>
}
=
Object
.
create
(
null
);
constructor
(
private
_hashFn
:
(
element
:
T
)
=>
string
)
{
constructor
(
private
_hashFn
:
(
element
:
T
)
=>
string
)
{
// empty
}
public
roots
():
Node
<
T
>
[]
{
var
ret
:
Node
<
T
>
[]
=
[];
collections
.
forEach
(
this
.
_nodes
,
entry
=>
{
if
(
objects
.
isEmptyObject
(
entry
.
value
.
outgoing
))
{
roots
():
Node
<
T
>
[]
{
var
ret
:
Node
<
T
>
[]
=
[];
forEach
(
this
.
_nodes
,
entry
=>
{
if
(
isEmptyObject
(
entry
.
value
.
outgoing
))
{
ret
.
push
(
entry
.
value
);
}
});
return
ret
;
}
public
traverse
(
start
:
T
,
inwards
:
boolean
,
callback
:(
data
:
T
)
=>
void
):
void
{
traverse
(
start
:
T
,
inwards
:
boolean
,
callback
:
(
data
:
T
)
=>
void
):
void
{
var
startNode
=
this
.
lookup
(
start
);
if
(
!
startNode
)
{
if
(
!
startNode
)
{
return
;
}
this
.
_traverse
(
startNode
,
inwards
,
{},
callback
);
}
private
_traverse
(
node
:
Node
<
T
>
,
inwards
:
boolean
,
seen
:{[
key
:
string
]:
boolean
},
callback
:(
data
:
T
)
=>
void
):
void
{
private
_traverse
(
node
:
Node
<
T
>
,
inwards
:
boolean
,
seen
:
{
[
key
:
string
]:
boolean
},
callback
:
(
data
:
T
)
=>
void
):
void
{
var
key
=
this
.
_hashFn
(
node
.
data
);
if
(
collections
.
contains
(
seen
,
key
))
{
if
(
contains
(
seen
,
key
))
{
return
;
}
seen
[
key
]
=
true
;
callback
(
node
.
data
);
var
nodes
=
inwards
?
node
.
outgoing
:
node
.
incoming
;
collections
.
forEach
(
nodes
,
(
entry
)
=>
this
.
_traverse
(
entry
.
value
,
inwards
,
seen
,
callback
));
forEach
(
nodes
,
(
entry
)
=>
this
.
_traverse
(
entry
.
value
,
inwards
,
seen
,
callback
));
}
public
insertEdge
(
from
:
T
,
to
:
T
):
void
{
var
fromNode
=
this
.
lookupOrInsertNode
(
from
),
insertEdge
(
from
:
T
,
to
:
T
):
void
{
var
fromNode
=
this
.
lookupOrInsertNode
(
from
),
toNode
=
this
.
lookupOrInsertNode
(
to
);
fromNode
.
outgoing
[
this
.
_hashFn
(
to
)]
=
toNode
;
toNode
.
incoming
[
this
.
_hashFn
(
from
)]
=
fromNode
;
}
public
removeNode
(
data
:
T
):
void
{
removeNode
(
data
:
T
):
void
{
var
key
=
this
.
_hashFn
(
data
);
delete
this
.
_nodes
[
key
];
collections
.
forEach
(
this
.
_nodes
,
(
entry
)
=>
{
forEach
(
this
.
_nodes
,
(
entry
)
=>
{
delete
entry
.
value
.
outgoing
[
key
];
delete
entry
.
value
.
incoming
[
key
];
});
}
public
lookupOrInsertNode
(
data
:
T
):
Node
<
T
>
{
lookupOrInsertNode
(
data
:
T
):
Node
<
T
>
{
var
key
=
this
.
_hashFn
(
data
),
node
=
collections
.
lookup
(
this
.
_nodes
,
key
);
node
=
lookup
(
this
.
_nodes
,
key
);
if
(
!
node
)
{
if
(
!
node
)
{
node
=
newNode
(
data
);
this
.
_nodes
[
key
]
=
node
;
}
...
...
@@ -87,11 +87,11 @@ export class Graph<T> {
return
node
;
}
public
lookup
(
data
:
T
):
Node
<
T
>
{
return
collections
.
lookup
(
this
.
_nodes
,
this
.
_hashFn
(
data
));
lookup
(
data
:
T
):
Node
<
T
>
{
return
lookup
(
this
.
_nodes
,
this
.
_hashFn
(
data
));
}
public
get
length
():
number
{
get
length
():
number
{
return
Object
.
keys
(
this
.
_nodes
).
length
;
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录