2021SC@SDUSC
今天接着上文细说walk()方法子类遍历能力的体现
目录
ReserveDependencyOrderWalker
ReserveDependencyOrderWalker是逆向的依赖顺序遍历,即一个节点访问之后才能访问它依赖的节点,即N节点要想被访问,需要依赖N节点的节点先被访问。
public PlanWalker spawnChildWalker(OperatorPlan plan) {
return new ReverseDependencyOrderWalker(plan);
}
walk()方法的访问模式类似DependencyOrderWalker,区别在于先获得所有的root节点,然后进行遍历操作,遍历root节点的所有后辈,递归后辈的后辈,使root节点最后访问。
递归如下:
protected void doAllSuccessors(Operator node,
Set<Operator> seen,
Collection<Operator> fifo) throws FrontendException {
if (!seen.contains(node)) {
// We haven't seen this one before.
Collection<Operator> succs = Utils.mergeCollection(plan.getSuccessors(node), plan.getSoftLinkSuccessors(node));
if (succs != null && succs.size() > 0) {
// Do all our successors before ourself
for (Operator op : succs) {
doAllSuccessors(op, seen, fifo);
}
}
// Now do ourself
seen.add(node);
fifo.add(node);
}
}