本文整理汇总了TypeScript中vs/base/common/map.TernarySearchTree类的典型用法代码示例。如果您正苦于以下问题:TypeScript TernarySearchTree类的具体用法?TypeScript TernarySearchTree怎么用?TypeScript TernarySearchTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TernarySearchTree类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: test
test('TernarySearchTree - set', function () {
let trie = TernarySearchTree.forStrings<number>();
trie.set('foobar', 1);
trie.set('foobaz', 2);
assertTernarySearchTree(trie, ['foobar', 1], ['foobaz', 2]); // longer
trie = TernarySearchTree.forStrings<number>();
trie.set('foobar', 1);
trie.set('fooba', 2);
assertTernarySearchTree(trie, ['foobar', 1], ['fooba', 2]); // shorter
trie = TernarySearchTree.forStrings<number>();
trie.set('foo', 1);
trie.set('foo', 2);
assertTernarySearchTree(trie, ['foo', 2]);
trie = TernarySearchTree.forStrings<number>();
trie.set('foo', 1);
trie.set('foobar', 2);
trie.set('bar', 3);
trie.set('foob', 4);
trie.set('bazz', 5);
assertTernarySearchTree(trie,
['foo', 1],
['foobar', 2],
['bar', 3],
['foob', 4],
['bazz', 5]
);
});
开发者ID:developers23,项目名称:vscode,代码行数:33,代码来源:map.test.ts
示例2:
function assertTernarySearchTree<E>(trie: TernarySearchTree<E>, ...elements: [string, E][]) {
const map = new Map<string, E>();
for (const [key, value] of elements) {
map.set(key, value);
}
map.forEach((value, key) => {
assert.equal(trie.get(key), value);
});
trie.forEach((element, key) => {
assert.equal(element, map.get(key));
map.delete(key);
});
assert.equal(map.size, 0);
}
开发者ID:developers23,项目名称:vscode,代码行数:14,代码来源:map.test.ts
示例3: test
test('TernarySearchTree (PathSegments) - superstr', function () {
const map = new TernarySearchTree<number>(new PathIterator());
map.set('/user/foo/bar', 1);
map.set('/user/foo', 2);
map.set('/user/foo/flip/flop', 3);
map.set('/usr/foo', 4);
const elements = map.findSuperstr('/user');
assertTernarySearchTree(elements, ['foo/bar', 1], ['foo', 2], ['foo/flip/flop', 3]);
// assert.equal(elements.length, 3);
assert.equal(elements.get('foo/bar'), 1);
assert.equal(elements.get('foo'), 2);
assert.equal(elements.get('foo/flip/flop'), 3);
assertTernarySearchTree(map.findSuperstr('/usr'), ['foo', 4]);
assert.equal(map.findSuperstr('/usr/foo'), undefined);
assert.equal(map.get('/usr/foo'), 4);
assert.equal(map.findSuperstr('/not'), undefined);
assert.equal(map.findSuperstr('/us'), undefined);
assert.equal(map.findSuperstr('/usrr'), undefined);
assert.equal(map.findSuperstr('/userr'), undefined);
});
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:25,代码来源:map.test.ts
注:本文中的vs/base/common/map.TernarySearchTree类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论