T- the type of the nodes
public class Digraph<T> extends Object
A directed graph is a data structure consisting of nodes and arrows connecting those nodes which are called edges. In a directed graph edges are ordered pairs of respectively source and target nodes.
This implementation is adapted to small in-memory graphs.
|Constructor and Description|
Constructs a directed graph from a specification Map.
|Modifier and Type||Method and Description|
Sort nodes in a topological ordering assuming that this graph is acyclic.
public Digraph(Map<T,Collection<T>> spec) throws IllegalArgumentException
spec- the map defining a set of source nodes (keys) that are linked to a collection of adjacent target nodes (values). Both keys and values must not be
IllegalArgumentException- when a target node is not present in the sources nodes.
public List<T> sort() throws IllegalStateException
A graph without cycles is often called a Directed Acyclic Graph (DAG).