This commit is contained in:
Johannes Rieken 2021-05-31 09:22:26 +02:00
parent 4f3d865a6b
commit 910d70bb88
No known key found for this signature in database
GPG key ID: 96634B5AF12F8798

View file

@ -497,10 +497,14 @@ export class TernarySearchTree<K, V> {
yield* this._entries(this._root);
}
private *_entries(node: TernarySearchTreeNode<K, V> | undefined): IterableIterator<[K, V]> {
private *_entries(node: TernarySearchTreeNode<K, V> | undefined, i: number = 0): IterableIterator<[K, V]> {
if (i > 5000) {
console.trace('potential CYCLE detected');
return;
}
if (node) {
// left
yield* this._entries(node.left);
yield* this._entries(node.left, i++);
// node
if (node.value) {
@ -508,10 +512,10 @@ export class TernarySearchTree<K, V> {
yield [node.key, node.value];
}
// mid
yield* this._entries(node.mid);
yield* this._entries(node.mid, i++);
// right
yield* this._entries(node.right);
yield* this._entries(node.right, i++);
}
}
}