Rev 3806: Clean up some little bits. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/prefix

John Arbash Meinel john at arbash-meinel.com
Fri Dec 12 22:35:44 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/brisbane/prefix

------------------------------------------------------------
revno: 3806
revision-id: john at arbash-meinel.com-20081212223534-y2h7xxe1yghd7l10
parent: john at arbash-meinel.com-20081212215251-6xt80zq6i7zmu9g7
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: prefix
timestamp: Fri 2008-12-12 16:35:34 -0600
message:
  Clean up some little bits.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py	2008-12-12 21:52:51 +0000
+++ b/bzrlib/chk_map.py	2008-12-12 22:35:34 +0000
@@ -444,17 +444,26 @@
     """A node containing actual key:value pairs.
 
     :ivar _items: A dict of key->value items. The key is in tuple form.
+    :ivar _size: The number of bytes that would be used by serializing all of
+        the key/value pairs.
     """
 
     def __init__(self):
         Node.__init__(self)
-        # The size of a leaf node with default values and no children.
-        self._size = 12
+        # All of the keys in this leaf node share this common prefix
+        self._common_prefix = None
 
     def _current_size(self):
-        """Answer the current serialised size of this node."""
-        return (self._size + len(str(self._len)) + len(str(self._key_width)) +
-            len(str(self._maximum_size)))
+        """Answer the current serialised size of this node.
+
+        This differs from self._size in that it includes the bytes used for the
+        header.
+        """
+        return (12 # bytes overhead for the header and separators
+            + len(str(self._len))
+            + len(str(self._key_width))
+            + len(str(self._maximum_size))
+            + self._size)
 
     @classmethod
     def deserialise(klass, bytes, key):
@@ -629,7 +638,7 @@
 
     def unmap(self, store, key):
         """Unmap key from the node."""
-        self._size -= 2 + len('\x00'.join(key)) + len(self._items[key])
+        self._size -= self._key_value_len(key, self._items[key])
         self._len -= 1
         del self._items[key]
         self._key = None
@@ -643,6 +652,9 @@
 
     An InternalNode is responsible for mapping serialised key prefixes to child
     nodes. It is greedy - it will defer splitting itself as long as possible.
+
+    :ivar _items: serialized_key => node dictionary. node may be a tuple,
+        LeafNode or InternalNode.
     """
 
     def __init__(self, prefix=''):



More information about the bazaar-commits mailing list