don't use recursion for _entries, https://github.com/microsoft/vscode/issues/124723
This commit is contained in:
parent
692ffc0225
commit
229f018be9
2 changed files with 23 additions and 16 deletions
|
@ -498,20 +498,27 @@ export class TernarySearchTree<K, V> {
|
|||
}
|
||||
|
||||
private *_entries(node: TernarySearchTreeNode<K, V> | undefined): IterableIterator<[K, V]> {
|
||||
if (node) {
|
||||
// left
|
||||
yield* this._entries(node.left);
|
||||
|
||||
// node
|
||||
if (node.value) {
|
||||
// callback(node.value, this._iter.join(parts));
|
||||
yield [node.key, node.value];
|
||||
// DFS
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
const stack = [node];
|
||||
while (stack.length > 0) {
|
||||
const node = stack.pop();
|
||||
if (node) {
|
||||
if (node.value) {
|
||||
yield [node.key, node.value];
|
||||
}
|
||||
if (node.left) {
|
||||
stack.push(node.left);
|
||||
}
|
||||
if (node.mid) {
|
||||
stack.push(node.mid);
|
||||
}
|
||||
if (node.right) {
|
||||
stack.push(node.right);
|
||||
}
|
||||
}
|
||||
// mid
|
||||
yield* this._entries(node.mid);
|
||||
|
||||
// right
|
||||
yield* this._entries(node.right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -762,6 +762,9 @@ suite('Map', () => {
|
|||
|
||||
iter = map.findSuperstr(URI.file('/'))!;
|
||||
item = iter.next();
|
||||
assert.strictEqual(item.value[1], 4);
|
||||
assert.strictEqual(item.done, false);
|
||||
item = iter.next();
|
||||
assert.strictEqual(item.value[1], 2);
|
||||
assert.strictEqual(item.done, false);
|
||||
item = iter.next();
|
||||
|
@ -771,9 +774,6 @@ suite('Map', () => {
|
|||
assert.strictEqual(item.value[1], 3);
|
||||
assert.strictEqual(item.done, false);
|
||||
item = iter.next();
|
||||
assert.strictEqual(item.value[1], 4);
|
||||
assert.strictEqual(item.done, false);
|
||||
item = iter.next();
|
||||
assert.strictEqual(item.value, undefined);
|
||||
assert.strictEqual(item.done, true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue