[pypy-svn] r18090 - pypy/dist/pypy/tool/algo

arigo at codespeak.net arigo at codespeak.net
Mon Oct 3 01:39:52 CEST 2005


Author: arigo
Date: Mon Oct  3 01:39:52 2005
New Revision: 18090

Modified:
   pypy/dist/pypy/tool/algo/graphlib.py
Log:
utility to turn a list of edges into the dict format expected by graphlib.


Modified: pypy/dist/pypy/tool/algo/graphlib.py
==============================================================================
--- pypy/dist/pypy/tool/algo/graphlib.py	(original)
+++ pypy/dist/pypy/tool/algo/graphlib.py	Mon Oct  3 01:39:52 2005
@@ -4,6 +4,7 @@
 Convention:
   'vertices' is a set of vertices (or a dict with vertices as keys);
   'edges' is a dict mapping vertices to a list of edges with its source.
+  Note that we can usually use 'edges' as the set of 'vertices' too.
 """
 
 class Edge:
@@ -11,6 +12,13 @@
         self.source = source
         self.target = target
 
+def make_edge_dict(edge_list):
+    "Put a list of edges in the official dict format."
+    edges = {}
+    for edge in edge_list:
+        edges.setdefault(edge.source, []).append(edge)
+    return edges
+
 def depth_first_search(root, vertices, edges):
     seen = {}
     result = []



More information about the Pypy-commit mailing list