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

fijal at codespeak.net fijal at codespeak.net
Tue Oct 23 01:11:53 CEST 2007


Author: fijal
Date: Tue Oct 23 01:11:51 2007
New Revision: 47721

Modified:
   pypy/dist/pypy/tool/algo/graphlib.py
Log:
This is apparently faster :-/


Modified: pypy/dist/pypy/tool/algo/graphlib.py
==============================================================================
--- pypy/dist/pypy/tool/algo/graphlib.py	(original)
+++ pypy/dist/pypy/tool/algo/graphlib.py	Tue Oct 23 01:11:51 2007
@@ -95,7 +95,7 @@
             if stackpos[v] is not None:   # back-edge
                 result.append(edgestack[stackpos[v]:])
     visit(root)
-    return result
+    return result        
 
 def break_cycles(vertices, edges):
     """Enumerates a reasonably minimal set of edges that must be removed to
@@ -111,7 +111,10 @@
             for cycle in all_cycles(random_vertex, component, edges):
                 #print '\tcycle:', [e.source+e.target for e in cycle]
                 for edge in cycle:
-                    edge_weights[edge] = edge_weights.get(edge, 0) + 1
+                    try:
+                        edge_weights[edge] += 1
+                    except KeyError:
+                        edge_weights[edge] = 1
             if edge_weights:
                 max_weight = max(edge_weights.values())
                 for edge, weight in edge_weights.iteritems():



More information about the Pypy-commit mailing list