[Checkins] SVN: zc.dict/branches/tlotze-blist/ changed the implementation of OrderedDict to store the order in buckets

Thomas Lotze tl at gocept.com
Tue Dec 23 05:39:05 EST 2008


Log message for revision 94272:
  changed the implementation of OrderedDict to store the order in buckets
  (still need to think about implications on other parts of the implementation
  and add a generation)
  

Changed:
  U   zc.dict/branches/tlotze-blist/CHANGES.txt
  U   zc.dict/branches/tlotze-blist/setup.py
  U   zc.dict/branches/tlotze-blist/src/zc/dict/dict.py
  U   zc.dict/branches/tlotze-blist/src/zc/dict/ordered.txt

-=-
Modified: zc.dict/branches/tlotze-blist/CHANGES.txt
===================================================================
--- zc.dict/branches/tlotze-blist/CHANGES.txt	2008-12-23 10:36:22 UTC (rev 94271)
+++ zc.dict/branches/tlotze-blist/CHANGES.txt	2008-12-23 10:39:05 UTC (rev 94272)
@@ -1,3 +1,8 @@
+1.3 (unreleased)
+----------------
+
+* changed the implementation of OrderedDict to store the order in buckets
+
 1.2.1 (2007-3-5)
 ----------------
 

Modified: zc.dict/branches/tlotze-blist/setup.py
===================================================================
--- zc.dict/branches/tlotze-blist/setup.py	2008-12-23 10:36:22 UTC (rev 94271)
+++ zc.dict/branches/tlotze-blist/setup.py	2008-12-23 10:39:05 UTC (rev 94272)
@@ -14,7 +14,7 @@
     packages=["zc", "zc.dict"],
     package_dir={"": "src"},
     include_package_data=True,
-    install_requires=["setuptools", "zope.interface", "ZODB3"],
+    install_requires=["setuptools", "zope.interface", "ZODB3", "zc.blist"],
     tests_require=["zope.testing"],
     description=open('README.txt').read(),
     long_description=long_description,

Modified: zc.dict/branches/tlotze-blist/src/zc/dict/dict.py
===================================================================
--- zc.dict/branches/tlotze-blist/src/zc/dict/dict.py	2008-12-23 10:36:22 UTC (rev 94271)
+++ zc.dict/branches/tlotze-blist/src/zc/dict/dict.py	2008-12-23 10:39:05 UTC (rev 94272)
@@ -20,7 +20,7 @@
 import BTrees
 import BTrees.Length
 import persistent
-import persistent.list
+import zc.blist
 
 
 class Dict(persistent.Persistent):
@@ -129,9 +129,7 @@
 class OrderedDict(Dict):
     """A Ordered BTree-based dict-like persistent object that can be safely
     inherited from.
-    
-    This class does not have as good behavior with large numbers of members
-    as the Dict class because the _order object is not in buckets.
+
     """
 
     # what do we get from the superclass:
@@ -139,11 +137,11 @@
     # get, __delitem__
 
     def __init__(self, *args, **kwargs):
-        self._order = persistent.list.PersistentList()
+        self._order = zc.blist.BList()
         super(OrderedDict, self).__init__(*args, **kwargs)
 
     def keys(self):
-        return self._order[:]
+        return list(self._order)
 
     def __iter__(self):
         return iter(self._order)
@@ -164,7 +162,7 @@
             self._len.change(delta)
 
     def updateOrder(self, order):
-        order = persistent.list.PersistentList(order)
+        order = zc.blist.BList(order)
 
         if len(order) != len(self._order):
             raise ValueError("Incompatible key set.")
@@ -190,7 +188,7 @@
         order = self._order
         try:
             self._data = OOBTree()
-            self._order = persistent.list.PersistentList()
+            self._order = zc.blist.BList()
             c = copy.copy(self)
         finally:
             self._data = data

Modified: zc.dict/branches/tlotze-blist/src/zc/dict/ordered.txt
===================================================================
--- zc.dict/branches/tlotze-blist/src/zc/dict/ordered.txt	2008-12-23 10:36:22 UTC (rev 94271)
+++ zc.dict/branches/tlotze-blist/src/zc/dict/ordered.txt	2008-12-23 10:39:05 UTC (rev 94272)
@@ -5,12 +5,6 @@
 additional feature that it remembers the order in which items were added.
 It also provides the API to reorder the items.
 
-Importantly, the OrderedDict currently uses a PersistentList to store
-the order, which does not have good behavior for large collections,
-because the entire collection of keys must be pickled every time any
-key, or ordering, changes.  A BList would be a preferred data structure,
-but that has not yet been released.
-
     >>> from zc.dict import OrderedDict
     >>> d = OrderedDict()
     >>> d
@@ -172,9 +166,9 @@
 However, efficient iterators are available via the iter methods:
 
     >>> iter(d)
-    <iterator object at ...>
+    <generator object at ...>
     >>> d.iterkeys()
-    <iterator object at ...>
+    <generator object at ...>
  
     >>> d.iteritems()
     <generator object at ...>



More information about the Checkins mailing list