com.almondtools.util.graph.ReversePostOrderTraversal Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rexlex Show documentation
Show all versions of rexlex Show documentation
Regular expression matchers, searcher, lexers based on deterministic finite automata
package com.almondtools.util.graph;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public abstract class ReversePostOrderTraversal extends AbstractTraversal implements Traversal {
private Set> visited;
private List> ordered;
public ReversePostOrderTraversal(Graph graph) {
super(graph);
this.visited = new HashSet>();
this.ordered = new LinkedList>();
}
@Override
public void traverse() {
super.traverse();
for (GraphNode node : ordered) {
visitGraphNode(node);
}
}
@Override
public void traverseNode(GraphNode node) {
if (!visited.contains(node)) {
visited.add(node);
for (GraphNode next : node.getSuccessors()) {
next.apply(this);
}
record(node);
}
}
private void record(GraphNode node) {
ordered.add(0, node);
}
public abstract void visitGraphNode(GraphNode node);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy