Add a class for handling topological sorts for dependency graphs.
Review Request #7722 — Created Oct. 21, 2015 and submitted
DependencyGraph manages a graph of items and their dependencies, and can generate a list of items in dependency order. This will be used for determining the correct order in which to install packages.
Unit tests pass.
Description | From | Last Updated |
---|---|---|
"Vertice" isn't a word. "Vertex" is. |
david | |
Hrm. It bugs me that we're manipulating state on the vertices themselves to do this. Can we have a visited … |
david | |
Why do we maintain both this list and this dictionary? Can't we just use the dictionary? The only time a … |
AD adriano | |
Consider replacing "and dependencies" with "and its dependencies". |
AD adriano | |
This is usally called toposort |
brennie | |
I think "yielding" should be "yield". As in: "This will recursively...yield all results." |
AD adriano | |
This sounds a bit funny to me. We don't really sort a single vertex; we sort all the vertices in … |
AD adriano |
- Change Summary:
-
- Stopped inventing words.
- Removed the
visited
flag onVertex
, switching to a local cache used during sort.
-
Tool: Pyflakes Processed Files: rbpkg/package_manager/dep_graph.py rbpkg/package_manager/tests/test_dep_graph.py Ignored Files: rbpkg/package_manager/__init__.py Tool: PEP8 Style Checker Processed Files: rbpkg/package_manager/dep_graph.py rbpkg/package_manager/tests/test_dep_graph.py Ignored Files: rbpkg/package_manager/__init__.py
-
There's a typo in the summary: "toplogical" -> "topological".
-
It seems that
edges
is a list of vertices, as opposed to a list of directed edges in the usual graph theory sense (which to me would be ordered pairs of vertices). So perhaps a better name would beneighbours
, since it's the list of all neighbouring vertices? -
Why do we maintain both this list and this dictionary? Can't we just use the dictionary? The only time a call to
self._vertices
is made is when we iterate through all the vertices in Line 74. It doesn't seem like the order matters. So we could get rid ofself._vertices
and replace Line 74 with:for vertex in six.itervalues(self._vertex_cache)
If it turns out that the order in which the vertices are added to the graph does matter, then we could always use an
OrderedDict
. -
-
-
This sounds a bit funny to me. We don't really sort a single vertex; we sort all the vertices in the graph. Perhaps replace it with something like "The starting vertex of the topological sort."
-
I'm curious: instead of the try/except, why not do something like:
if item in self._vertex_cache: return self._vertex_cache[item] else: # ... append it to the vertices and return it ...
- Change Summary:
-
- Added
__contains__
, for checking if an item is in the graph. - Renamed
_tsort
to_toposort
. - Changed some docstrings, based on feedback.
- Added
- Summary:
-
Add a class for handling toplogical sorts for dependency graphs.Add a class for handling topological sorts for dependency graphs.
-
Tool: PEP8 Style Checker Processed Files: rbpkg/package_manager/dep_graph.py rbpkg/package_manager/tests/test_dep_graph.py Ignored Files: rbpkg/package_manager/__init__.py Tool: Pyflakes Processed Files: rbpkg/package_manager/dep_graph.py rbpkg/package_manager/tests/test_dep_graph.py Ignored Files: rbpkg/package_manager/__init__.py
-
Tool: PEP8 Style Checker Processed Files: rbpkg/package_manager/dep_graph.py rbpkg/package_manager/tests/test_dep_graph.py Ignored Files: rbpkg/package_manager/__init__.py Tool: Pyflakes Processed Files: rbpkg/package_manager/dep_graph.py rbpkg/package_manager/tests/test_dep_graph.py Ignored Files: rbpkg/package_manager/__init__.py