Revision: 5711
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5711&view=rev
Author:   mdboom
Date:     2008-07-03 09:08:52 -0700 (Thu, 03 Jul 2008)

Log Message:
-----------
O(n) implementation of Grouper.__iter__

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/cbook.py

Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py    2008-07-03 14:30:41 UTC (rev 
5710)
+++ trunk/matplotlib/lib/matplotlib/cbook.py    2008-07-03 16:08:52 UTC (rev 
5711)
@@ -1030,7 +1030,7 @@
     >>> g.join('a', 'b')
     >>> g.join('b', 'c')
     >>> g.join('d', 'e')
-    >>> list(g.get())
+    >>> list(g)
     [['a', 'b', 'c'], ['d', 'e']]
     >>> g.joined('a', 'b')
     True
@@ -1079,14 +1079,25 @@
 
     def __iter__(self):
         """
-        Returns an iterator yielding each of the disjoint sets as a list.
+        Iterate over each of the disjoint sets as a list.
+
+        The iterator is invalid if interleaved with calls to join().
         """
-        seen = set()
-        for elem, group in self._mapping.iteritems():
-            if elem not in seen:
+        class Token: pass
+        token = Token()
+
+        # Mark each group as we come across if by appending a token,
+        # and don't yield it twice
+        for group in self._mapping.itervalues():
+            if not group[-1] is token:
                 yield group
-                seen.update(group)
+                group.append(token)
 
+        # Cleanup the tokens
+        for group in self._mapping.itervalues():
+            if group[-1] is token:
+                del group[-1]
+
     def get_siblings(self, a):
         """
         Returns all of the items joined with *a*, including itself.


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to