Page MenuHomePhabricator

Implement getBestEffortTopographicallySortedNodesByRow on AbstractDirectedGraph
ClosedPublic

Authored by hach-que on Jul 17 2014, 3:19 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Aug 25, 2:23 PM
Unknown Object (File)
Sun, Aug 25, 8:34 AM
Unknown Object (File)
Sun, Aug 25, 8:29 AM
Unknown Object (File)
Sun, Aug 25, 6:08 AM
Unknown Object (File)
Mon, Aug 19, 11:06 AM
Unknown Object (File)
Sat, Aug 17, 8:08 AM
Unknown Object (File)
Wed, Aug 14, 10:43 AM
Unknown Object (File)
Aug 7 2024, 6:35 AM
Subscribers

Details

Diff Detail

Repository
rPHU libphutil
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

hach-que retitled this revision from to Implement getBestEffortTopographicallySortedNodesByRow on AbstractDirectedGraph.
hach-que updated this object.
hach-que edited the test plan for this revision. (Show Details)
hach-que added a reviewer: epriestley.
epriestley edited edge metadata.
epriestley added inline comments.
src/utils/AbstractDirectedGraph.php
159–161

Since in_array() is O(N), this makes the algorithm O(N^2).

Use keys in $completed -- like $completed[$node] = true -- and isset($completed[$node]) instead, which is O(1).

Or, remove nodes from the list of remaining nodes after they're added to the results.

176–180

This seems like an odd return value.

Instead, suppose we choose one node at random/arbitrarily and mark it completed, so we always produce an ordering on all of the items (a "best effort" ordering)?

Then we could return a list of something like this:

array(
  'node' => $node,
  'depth' => /* the minimum distance from the root to the node */,
  'cycle' => /* true if we had to force our way through a cycle before we could complete this node */
)

That should be everything you need to render the data in Harbormaster.

This revision now requires changes to proceed.Jul 17 2014, 9:43 PM
hach-que edited edge metadata.

Changes based on feedback

hach-que edited edge metadata.

Actually write code that works

epriestley edited edge metadata.
This revision is now accepted and ready to land.Jul 18 2014, 2:09 AM
hach-que updated this revision to Diff 23981.

Closed by commit rPHU8ddea4ef8c67 (authored by @hach-que).