Class NodeSorting
java.lang.Object
net.fabricmc.fabric.impl.base.toposort.NodeSorting
Contains a topological sort implementation, with tie breaking using a
Comparator.
The final order is always deterministic (i.e. doesn't change with the order of the input elements or the edges), assuming that they are all different according to the comparator. This also holds in the presence of cycles.
The steps are as follows:
- Compute node SCCs (Strongly Connected Components, i.e. cycles).
- Sort nodes within SCCs using the comparator.
- Sort SCCs with respect to each other by respecting constraints, and using the comparator in case of a tie.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <N extends SortableNode<N>>
booleansort(List<N> sortedNodes, String elementDescription, Comparator<N> comparator) Sort a list of nodes.
-
Field Details
-
ENABLE_CYCLE_WARNING
public static boolean ENABLE_CYCLE_WARNING
-
-
Constructor Details
-
NodeSorting
public NodeSorting()
-
-
Method Details
-
sort
public static <N extends SortableNode<N>> boolean sort(List<N> sortedNodes, String elementDescription, Comparator<N> comparator) Sort a list of nodes.- Parameters:
sortedNodes- The list of nodes to sort. Will be modified in-place.elementDescription- A description of the elements, used for logging in the presence of cycles.comparator- The comparator to break ties and to order elements within a cycle.- Returns:
trueif all the constraints were satisfied,falseif there was at least one cycle.
-