Rev 4773: Create a Barrier at the CHKMap interface. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple-chk-map

John Arbash Meinel john at arbash-meinel.com
Wed Oct 21 19:50:27 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple-chk-map

------------------------------------------------------------
revno: 4773
revision-id: john at arbash-meinel.com-20091021185008-8t37d9j69t0yo2vg
parent: john at arbash-meinel.com-20091021170247-wrxl9tee83r1arnb
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-static-tuple-chk-map
timestamp: Wed 2009-10-21 13:50:08 -0500
message:
  Create a Barrier at the CHKMap interface.
  
  Basically, everything above CHKMap can work in either tuples or StaticTuples.
  Everything *below* CHKMap should be working in StaticTuples.
  I need to fix .iteritems() but apply_delta, map, unmap, from_dict, etc are
  all handled.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py	2009-10-21 16:52:18 +0000
+++ b/bzrlib/chk_map.py	2009-10-21 18:50:08 +0000
@@ -115,8 +115,9 @@
         """
         delete_count = 0
         # Check preconditions first.
-        new_items = set([key for (old, key, value) in delta if key is not None
-            and old is None])
+        as_st = StaticTuple.from_sequence
+        new_items = set([as_st(key) for (old, key, value) in delta
+                         if key is not None and old is None])
         existing_new = list(self.iteritems(key_filter=new_items))
         if existing_new:
             raise errors.InconsistentDeltaDelta(delta,
@@ -242,9 +243,11 @@
         node = LeafNode(search_key_func=search_key_func)
         node.set_maximum_size(maximum_size)
         node._key_width = key_width
-        node._items = dict(initial_value)
+        as_st = StaticTuple.from_sequence
+        node._items = dict([(as_st(key), val) for key, val
+                                               in initial_value.iteritems()])
         node._raw_size = sum([node._key_value_len(key, value)
-                              for key,value in initial_value.iteritems()])
+                              for key,value in node._items.iteritems()])
         node._len = len(node._items)
         node._compute_search_prefix()
         node._compute_serialised_prefix()
@@ -490,6 +493,7 @@
     def iteritems(self, key_filter=None):
         """Iterate over the entire CHKMap's contents."""
         self._ensure_root()
+        # TODO: StaticTuple Barrier here
         return self._root_node.iteritems(self._store, key_filter=key_filter)
 
     def key(self):
@@ -510,6 +514,7 @@
         :param key: A key to map.
         :param value: The value to assign to key.
         """
+        key = StaticTuple.from_sequence(key)
         # Need a root object.
         self._ensure_root()
         prefix, node_details = self._root_node.map(self._store, key, value)
@@ -525,17 +530,17 @@
 
     def _node_key(self, node):
         """Get the key for a node whether it's a tuple or node."""
+        if type(node) is tuple:
+            node = StaticTuple.from_sequence(node)
         if type(node) is StaticTuple:
             _check_key(node)
             return node
-        elif type(node) is tuple:
-            raise TypeError('node %r should be a StaticTuple not tuple'
-                            % (node,))
         else:
             return node._key
 
     def unmap(self, key, check_remap=True):
         """remove key from the map."""
+        key = StaticTuple.from_sequence(key)
         self._ensure_root()
         if type(self._root_node) is InternalNode:
             unmapped = self._root_node.unmap(self._store, key,
@@ -559,6 +564,7 @@
             # Already saved.
             return self._root_node
         keys = list(self._root_node.serialise(self._store))
+        assert type(keys[-1]) is StaticTuple
         return keys[-1]
 
 

=== modified file 'bzrlib/tests/test_chk_map.py'
--- a/bzrlib/tests/test_chk_map.py	2009-10-20 22:13:23 +0000
+++ b/bzrlib/tests/test_chk_map.py	2009-10-21 18:50:08 +0000
@@ -74,7 +74,6 @@
                  search_key_func=None):
         if chk_bytes is None:
             chk_bytes = self.get_chk_bytes()
-        a_dict = dict((StaticTuple(*k), v) for k, v in a_dict.iteritems())
         root_key = CHKMap.from_dict(chk_bytes, a_dict,
             maximum_size=maximum_size, key_width=key_width,
             search_key_func=search_key_func)



More information about the bazaar-commits mailing list