Page MenuHomePhabricator

D9956.id23974.diff
No OneTemporary

D9956.id23974.diff

diff --git a/src/utils/AbstractDirectedGraph.php b/src/utils/AbstractDirectedGraph.php
--- a/src/utils/AbstractDirectedGraph.php
+++ b/src/utils/AbstractDirectedGraph.php
@@ -142,6 +142,70 @@
}
/**
+ * Utility function to get the best effort of a list of rows of
+ * topographically sorted nodes out of a graph.
+ */
+ final public function getBestEffortTopographicallySortedNodesByRow() {
+ $nodes = $this->getNodes();
+ $edges = $this->loadEdges($nodes);
+
+ $results = array();
+ $completed = array();
+
+ $depth = 0;
+ while (true) {
+ $next = array();
+
+ foreach ($nodes as $node) {
+ if (isset($completed, $node)) {
+ continue;
+ }
+
+ $capable = true;
+ foreach ($edges[$node] as $edge) {
+ if (!isset($completed, $edge)) {
+ $capable = false;
+ break;
+ }
+ }
+
+ if ($capable) {
+ $next[] = $node;
+ }
+ }
+
+ if (count($next) === 0) {
+ // No more nodes to traverse; we are deadlocked if the number
+ // of completed nodes is less than the total number of nodes.
+ $depth++;
+ break;
+ }
+
+ foreach ($next as $node) {
+ $results[] = array(
+ 'node' => $next,
+ 'depth' => $depth,
+ 'cycle' => false);
+
+ $completed[$node] = true;
+ }
+
+ $depth++;
+ }
+
+ foreach ($nodes as $node) {
+ if (!isset($completed, $edge)) {
+ $results[] = array(
+ 'node' => $next,
+ 'depth' => $depth,
+ 'cycle' => false);
+ }
+ }
+
+ return $results;
+ }
+
+ /**
* Load the graph, building it out so operations can be performed on it. This
* constructs the graph level-by-level, calling @{method:loadEdges} to
* expand the graph at each stage until it is complete.

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 29, 2:00 AM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7708512
Default Alt Text
D9956.id23974.diff (1 KB)

Event Timeline