Class TopologicalSort<T>

java.lang.Object
org.eclipse.jetty.util.TopologicalSort<T>
Type Parameters:
T - The type to be sorted. It must be able to be added to a HashSet

public class TopologicalSort<T> extends Object
Topological sort a list or array.

A Topological sort is used when you have a partial ordering expressed as dependencies between elements (also often represented as edges in a directed acyclic graph). A Topological sort should not be used when you have a total ordering expressed as a Comparator over the items. The algorithm has the additional characteristic that dependency sets are sorted by the original list order so that order is preserved when possible.

The sort algorithm works by recursively visiting every item, once and only once. On each visit, the items dependencies are first visited and then the item is added to the sorted list. Thus the algorithm ensures that dependency items are always added before dependent items.