|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dellroad.stuff.graph.TopologicalSorter<E>
public class TopologicalSorter<E>
Topological sorting utility class.
| Nested Class Summary | |
|---|---|
static interface |
TopologicalSorter.EdgeLister<E>
Implemented by classes that can enumerate the outgoing edges from a node in a graph. |
| Constructor Summary | |
|---|---|
TopologicalSorter(Collection<E> nodes,
TopologicalSorter.EdgeLister<E> edgeLister)
Convenience constructor for when ties should be broken based on the original ordering. |
|
TopologicalSorter(Collection<E> nodes,
TopologicalSorter.EdgeLister<E> edgeLister,
Comparator<? super E> tieBreaker)
Primary constructor. |
|
| Method Summary | |
|---|---|
List<E> |
sort()
Produce a total ordering of the nodes consistent with the partial ordering implied by the edge lister and tie breaker provided to the constructor. |
List<E> |
sortEdgesReversed()
Same as sort() but treats all edges as reversed. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TopologicalSorter(Collection<E> nodes,
TopologicalSorter.EdgeLister<E> edgeLister,
Comparator<? super E> tieBreaker)
nodes - partially ordered nodes to be sortededgeLister - provides the edges defining the partial ordertieBreaker - used to sort nodes that are not otherwise ordered,
or null to tie break based on the original ordering
public TopologicalSorter(Collection<E> nodes,
TopologicalSorter.EdgeLister<E> edgeLister)
Equivalent to:
TopologicalSorter(nodes, edgeLister, null);
| Method Detail |
|---|
public List<E> sort()
The returned list will have the property that if there is an edge from X to Y, then X will appear before Y in the list. If there is no edge (or sequence of edges) from X to Y in either direction, then X will appear before Y if the tie breaker sorts X before Y.
This implementation runs in linear time in the number of nodes in the graph.
IllegalArgumentException - if the partial ordering relation contains a cyclepublic List<E> sortEdgesReversed()
sort() but treats all edges as reversed.
The returned list will have the property that if there is an edge from X to Y, then Y will appear before X in the list. If there is no edge (or sequence of edges) from X to Y in either direction, then X will appear before Y if the tie breaker sorts X before Y.
IllegalArgumentException - if the partial ordering relation contains a cycle
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||