Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
5bacd045
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,发现更多精彩内容 >>
提交
5bacd045
编写于
10月 20, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - move TrieMap to map.ts, add tests
上级
ecdfddab
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
94 addition
and
67 deletion
+94
-67
src/vs/base/common/map.ts
src/vs/base/common/map.ts
+72
-0
src/vs/base/test/common/map.test.ts
src/vs/base/test/common/map.test.ts
+20
-1
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+2
-66
未找到文件。
src/vs/base/common/map.ts
浏览文件 @
5bacd045
...
...
@@ -296,3 +296,75 @@ export class LRUCache<T> extends BoundedLinkedMap<T> {
return
null
;
}
}
// --- trie'ish datastructure
interface
Node
<
E
>
{
element
?:
E
;
children
:
{
[
key
:
string
]:
Node
<
E
>
};
}
/**
* A trie map that allows for fast look up when keys are substrings
* to the actual search keys (dir/subdir-problem).
*/
export
class
TrieMap
<
E
>
{
static
PathSplitter
=
s
=>
s
.
split
(
/
[\\/]
/
);
private
_splitter
:
(
s
:
string
)
=>
string
[];
private
_root
:
Node
<
E
>
=
{
children
:
Object
.
create
(
null
)
};
constructor
(
splitter
:
(
s
:
string
)
=>
string
[])
{
this
.
_splitter
=
splitter
;
}
insert
(
path
:
string
,
element
:
E
):
void
{
const
parts
=
this
.
_splitter
(
path
);
let
i
=
0
;
// find insertion node
let
node
=
this
.
_root
;
for
(;
i
<
parts
.
length
;
i
++
)
{
let
child
=
node
.
children
[
parts
[
i
]];
if
(
child
)
{
node
=
child
;
continue
;
}
break
;
}
// create new nodes
let
newNode
:
Node
<
E
>
;
for
(;
i
<
parts
.
length
;
i
++
)
{
newNode
=
{
children
:
Object
.
create
(
null
)
};
node
.
children
[
parts
[
i
]]
=
newNode
;
node
=
newNode
;
}
node
.
element
=
element
;
}
findSubstr
(
path
:
string
):
E
{
const
parts
=
this
.
_splitter
(
path
);
let
lastNode
:
Node
<
E
>
;
let
{
children
}
=
this
.
_root
;
for
(
const
part
of
parts
)
{
const
node
=
children
[
part
];
if
(
!
node
)
{
break
;
}
if
(
node
.
element
)
{
lastNode
=
node
;
}
children
=
node
.
children
;
}
// return the last matching node
// that had an element
if
(
lastNode
)
{
return
lastNode
.
element
;
}
}
}
src/vs/base/test/common/map.test.ts
浏览文件 @
5bacd045
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
BoundedLinkedMap
,
LRUCache
,
LinkedMap
}
from
'
vs/base/common/map
'
;
import
{
BoundedLinkedMap
,
LRUCache
,
LinkedMap
,
TrieMap
}
from
'
vs/base/common/map
'
;
import
*
as
assert
from
'
assert
'
;
suite
(
'
Map
'
,
()
=>
{
...
...
@@ -271,4 +271,23 @@ suite('Map', () => {
assert
.
ok
(
!
cache
.
has
(
'
3
'
));
assert
.
ok
(
!
cache
.
has
(
'
4
'
));
});
test
(
'
TrieMap - basics
'
,
function
()
{
const
map
=
new
TrieMap
<
number
>
(
TrieMap
.
PathSplitter
);
map
.
insert
(
'
/user/foo/bar
'
,
1
);
map
.
insert
(
'
/user/foo
'
,
2
);
map
.
insert
(
'
/user/foo/flip/flop
'
,
3
);
assert
.
equal
(
map
.
findSubstr
(
'
/user/bar
'
),
undefined
);
assert
.
equal
(
map
.
findSubstr
(
'
/user/foo
'
),
2
);
assert
.
equal
(
map
.
findSubstr
(
'
\\
user
\\
foo
'
),
2
);
assert
.
equal
(
map
.
findSubstr
(
'
/user/foo/ba
'
),
2
);
assert
.
equal
(
map
.
findSubstr
(
'
/user/foo/far/boo
'
),
2
);
assert
.
equal
(
map
.
findSubstr
(
'
/user/foo/bar
'
),
1
);
assert
.
equal
(
map
.
findSubstr
(
'
/user/foo/bar/far/boo
'
),
1
);
});
});
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
5bacd045
...
...
@@ -5,6 +5,7 @@
'
use strict
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
TrieMap
}
from
'
vs/base/common/map
'
;
import
{
score
}
from
'
vs/editor/common/modes/languageSelector
'
;
import
*
as
Platform
from
'
vs/base/common/platform
'
;
import
{
IThreadService
}
from
'
vs/workbench/services/thread/common/threadService
'
;
...
...
@@ -425,7 +426,7 @@ export function defineAPI(factory: IExtensionApiFactory, extensions: IExtensionD
let
defaultApiImpl
:
typeof
vscode
;
// create trie to enable fast 'filename -> extension id' look up
const
trie
=
new
TrieMap
<
IExtensionDescription
>
();
const
trie
=
new
TrieMap
<
IExtensionDescription
>
(
TrieMap
.
PathSplitter
);
for
(
const
ext
of
extensions
)
{
if
(
ext
.
name
)
{
const
path
=
realpathSync
(
ext
.
extensionFolderPath
);
...
...
@@ -457,68 +458,3 @@ export function defineAPI(factory: IExtensionApiFactory, extensions: IExtensionD
return
defaultApiImpl
;
};
}
// --- trie'ish datastructure
interface
Node
<
E
>
{
element
?:
E
;
children
:
{
[
key
:
string
]:
Node
<
E
>
};
}
class
TrieMap
<
E
>
{
private
static
_sep
=
/
[\\/]
/
;
private
_root
:
Node
<
E
>
=
{
children
:
Object
.
create
(
null
)
};
insert
(
path
:
string
,
element
:
E
):
void
{
const
parts
=
path
.
split
(
TrieMap
.
_sep
);
let
i
=
0
;
// find insertion node
let
node
=
this
.
_root
;
for
(;
i
<
parts
.
length
;
i
++
)
{
let
child
=
node
.
children
[
parts
[
i
]];
if
(
child
)
{
node
=
child
;
continue
;
}
break
;
}
// create new nodes
let
newNode
:
Node
<
E
>
;
for
(;
i
<
parts
.
length
;
i
++
)
{
newNode
=
{
children
:
Object
.
create
(
null
)
};
node
.
children
[
parts
[
i
]]
=
newNode
;
node
=
newNode
;
}
newNode
.
element
=
element
;
}
findSubstr
(
path
:
string
):
E
{
const
parts
=
path
.
split
(
TrieMap
.
_sep
);
let
lastNode
:
Node
<
E
>
;
let
{
children
}
=
this
.
_root
;
for
(
const
part
of
parts
)
{
const
node
=
children
[
part
];
if
(
!
node
)
{
break
;
}
if
(
node
.
element
)
{
lastNode
=
node
;
}
children
=
node
.
children
;
}
// return the last matching node
// that had an element
if
(
lastNode
)
{
return
lastNode
.
element
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录