Top Description Inners Fields Constructors Methods
org.antlr.v4.misc

public Class Graph<T>

extends Object
Class Inheritance
Imports
org.antlr.v4.runtime.misc.OrderedHashSet, java.util.ArrayList, .Collections, .LinkedHashMap, .List, .Map, .Set

A generic graph with edges; Each node as a single Object payload. This is only used to topologically sort a list of file dependencies at the moment.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
protected Map<T, Graph.Node<T>>
nodes

Map from node payload to node containing it

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addEdge(T a, T b)

public void
DFS(Graph.Node<T> n, Set<Graph.Node<T>> visited, ArrayList<T> sorted)

public Graph.Node<T>
getNode(T a)

public List<T>
sort()

DFS-based topological sort.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nodesback to summary
protected Map<T, Graph.Node<T>> nodes

Map from node payload to node containing it

Constructor Detail

Graphback to summary
public Graph()

Method Detail

addEdgeback to summary
public void addEdge(T a, T b)
DFSback to summary
public void DFS(Graph.Node<T> n, Set<Graph.Node<T>> visited, ArrayList<T> sorted)
getNodeback to summary
public Graph.Node<T> getNode(T a)
sortback to summary
public List<T> sort()

DFS-based topological sort. A valid sort is the reverse of the post-order DFA traversal. Amazingly simple but true. For sorting, I'm not following convention here since ANTLR needs the opposite. Here's what I assume for sorting: If there exists an edge u -> v then u depends on v and v must happen before u. So if this gives nonreversed postorder traversal, I get the order I want.

org.antlr.v4.misc back to summary

public Class Graph.Node<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public List<Graph.Node<T>>
public T

Constructor Summary

AccessConstructor and Description
public
Node(T payload)

Method Summary

Modifier and TypeMethod and Description
public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

edgesback to summary
public List<Graph.Node<T>> edges
Annotations
@SuppressWarnings:unchecked
payloadback to summary
public T payload

Constructor Detail

Nodeback to summary
public Node(T payload)

Method Detail

addEdgeback to summary
public void addEdge(Graph.Node<T> n)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override