本文整理匯總了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]
);
});
示例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);
}
示例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);
});