All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.almondtools.util.graph.ReversePostOrderTraversal Maven / Gradle / Ivy

Go to download

Regular expression matchers, searcher, lexers based on deterministic finite automata

There is a newer version: 0.3.3
Show newest version
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