blob: f2940a2abff513147bba5450f2171a8ebf310b7b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import { Node } from './node';
import { IWrap } from './wrap';
export class Enumerator {
public getAllNodes(root: IWrap<Node>): ReadonlyArray<IWrap<Node>> {
const nodes: Set<IWrap<Node>> = new Set();
const queue = [ root ];
while (queue.length !== 0) {
const node = queue.pop()!;
for (const slot of node.ref.getSlots()) {
if (nodes.has(slot.node)) {
continue;
}
nodes.add(slot.node);
queue.push(slot.node);
}
}
return Array.from(nodes);
}
}
|