[Zope-CVS] CVS: Packages/pypes/pypes - graph.py:1.9
    Casey Duncan 
    casey at zope.com
       
    Tue May 25 22:40:17 EDT 2004
    
    
  
Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv19497
Modified Files:
	graph.py 
Log Message:
Change iterTopological() to use abstract object markers and identity checks instead of integers and equality checks. Since one of the markers is None, this allows elimination of None equality checks. In theory this is a optimization, but it was done more for readability and correctness than performance.
=== Packages/pypes/pypes/graph.py 1.8 => 1.9 ===
--- Packages/pypes/pypes/graph.py:1.8	Sun Feb 29 00:44:48 2004
+++ Packages/pypes/pypes/graph.py	Tue May 25 22:40:16 2004
@@ -482,8 +482,8 @@
 
     def iterTopological(self):
         UNDISCOVERED = None
-        DISCOVERED = 1
-        EXPLORED = 2
+        DISCOVERED = object()
+        EXPLORED = object()
         status = {}
         nodes = []
         for n in self._nodes.keys():
@@ -491,7 +491,7 @@
                 nodes.append(n)
             while nodes:
                 dn = nodes[-1]
-                if status.get(dn) == EXPLORED:
+                if status.get(dn) is EXPLORED:
                     nodes.pop()
                 else:
                     referers, targets = self._nodes[dn]
@@ -501,17 +501,17 @@
                         if isinstance(targets, self._nodeSetFactory):
                             for t in targets:
                                 ts = status.get(t)
-                                if ts == UNDISCOVERED:
+                                if ts is UNDISCOVERED:
                                     is_explored = False
                                     nodes.append(t)
-                                elif ts == DISCOVERED:
+                                elif ts is DISCOVERED:
                                     raise GraphCycleError, t
                         else:
                             ts = status.get(targets)
-                            if ts == UNDISCOVERED:
+                            if ts is UNDISCOVERED:
                                 is_explored = False
                                 nodes.append(targets)
-                            elif ts == DISCOVERED:
+                            elif ts is DISCOVERED:
                                 raise GraphCycleError, targets
                     if is_explored:
                         status[dn] = EXPLORED
    
    
More information about the Zope-CVS
mailing list