java.lang.Object
org.jhotdraw8.graph.algo.TopologicalSortAlgo
Provides topological sort algorithms for directed graphs.
- Author:
- Werner Randelshofer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionsortTopologically(@NonNull Collection<V> vertices, @NonNull Function<V, Iterable<? extends V>> nextVertices) Sorts the specified directed graph topologically.sortTopologically(DirectedGraph<V, A> m) Sorts the specified directed graph topologically.int @NonNull []Sorts the specified directed graph topologically.Sorts the specified directed graph topologically.sortTopologicallyObject(@NonNull DirectedGraph<V, A> model) Sorts the specified directed graph topologically.
-
Constructor Details
-
TopologicalSortAlgo
public TopologicalSortAlgo()
-
-
Method Details
-
sortTopologically
Sorts the specified directed graph topologically.- Type Parameters:
V- the vertex data typeA- the arrow data type- Parameters:
m- the graph- Returns:
- the sorted list of vertices
-
sortTopologicallyInt
Sorts the specified directed graph topologically.- Parameters:
model- the graph- Returns:
- the sorted list of vertices
-
sortTopologicallyIntBatches
public @NonNull SimpleOrderedPair<int[],IntArrayList> sortTopologicallyIntBatches(@NonNull IndexedDirectedGraph model) Sorts the specified directed graph topologically. Returns a list of batches that do not depend topologically on each other.- Parameters:
model- the graph- Returns:
- the sorted list of vertices and the list of batches, batches will be empty if the graph has cycles
-
sortTopologicallyObject
Sorts the specified directed graph topologically.- Type Parameters:
V- the vertex data typeA- the arrow data type- Parameters:
model- the graph- Returns:
- the sorted list of vertices
-
sortTopologically
public <V> @NonNull List<V> sortTopologically(@NonNull Collection<V> vertices, @NonNull Function<V, Iterable<? extends V>> nextVertices) Sorts the specified directed graph topologically.If the graph contains cycles, then this method splits the graph inside a cycle.
- Type Parameters:
V- the vertex data type- Parameters:
vertices- the vertices of the graphnextVertices- a function that delivers the next vertices for a given vertex- Returns:
- the sorted list of vertices
-