Rev 3811: Start passing around the search_key_func in more places. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/hash_search_key
John Arbash Meinel
john at arbash-meinel.com
Wed Jan 21 19:40:06 GMT 2009
At http://bzr.arbash-meinel.com/branches/bzr/brisbane/hash_search_key
------------------------------------------------------------
revno: 3811
revision-id: john at arbash-meinel.com-20090121193956-ijxjv8tslli5vpir
parent: john at arbash-meinel.com-20090112225502-lb8om88nqe1u5o3g
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: hash_search_key
timestamp: Wed 2009-01-21 13:39:56 -0600
message:
Start passing around the search_key_func in more places.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py 2009-01-12 22:55:02 +0000
+++ b/bzrlib/chk_map.py 2009-01-21 19:39:56 +0000
@@ -53,8 +53,6 @@
_page_cache = lru_cache.LRUSizeCache(_PAGE_CACHE_SIZE)
-
-
class CHKMap(object):
"""A persistent map from string to string backed by a CHK store."""
@@ -115,7 +113,8 @@
"""
if type(node) == tuple:
bytes = self._read_bytes(node)
- return _deserialise(bytes, node)
+ return _deserialise(bytes, node,
+ search_key_func=self._search_key_func)
else:
return node
@@ -532,13 +531,13 @@
+ bytes_for_items)
@classmethod
- def deserialise(klass, bytes, key):
+ def deserialise(klass, bytes, key, search_key_func=None):
"""Deserialise bytes, with key key, into a LeafNode.
:param bytes: The bytes of the node.
:param key: The key that the serialised node has.
"""
- result = LeafNode()
+ result = LeafNode(search_key_func=search_key_func)
# Splitlines can split on '\r' so don't use it, split('\n') adds an
# extra '' if the bytes ends in a final newline.
lines = bytes.split('\n')
@@ -794,14 +793,14 @@
len(str(self._maximum_size)))
@classmethod
- def deserialise(klass, bytes, key):
+ def deserialise(klass, bytes, key, search_key_func=None):
"""Deserialise bytes to an InternalNode, with key key.
:param bytes: The bytes of the node.
:param key: The key that the serialised node has.
:return: An InternalNode instance.
"""
- result = InternalNode()
+ result = InternalNode(search_key_func=search_key_func)
# Splitlines can split on '\r' so don't use it, remove the extra ''
# from the result of split('\n') because we should have a trailing
# newline
@@ -881,7 +880,8 @@
except KeyError:
continue
else:
- node = _deserialise(bytes, key)
+ node = _deserialise(bytes, key,
+ search_key_func=self._search_key_func)
self._items[keys[key]] = node
found_keys.add(key)
yield node
@@ -901,7 +901,8 @@
nodes = []
for record in stream:
bytes = record.get_bytes_as('fulltext')
- node = _deserialise(bytes, record.key)
+ node = _deserialise(bytes, record.key,
+ search_key_func=self._search_key_func)
nodes.append(node)
self._items[keys[record.key]] = node
_page_cache.add(record.key, bytes)
@@ -920,8 +921,8 @@
# and then map this key into that node.
new_prefix = self.common_prefix(self._search_prefix,
search_key)
- # new_parent = InternalNode(new_prefix,
- # search_key_func=self._search_key_func)
+ new_parent = InternalNode(new_prefix,
+ search_key_func=self._search_key_func)
new_parent.set_maximum_size(self._maximum_size)
new_parent._key_width = self._key_width
new_parent.add_node(self._search_prefix[:len(new_prefix)+1],
@@ -972,6 +973,7 @@
child = klass()
child.set_maximum_size(self._maximum_size)
child._key_width = self._key_width
+ child._search_key_func = self._search_key_func
self._items[search_key] = child
return child
@@ -1113,7 +1115,7 @@
# and cause size changes greater than the length of one key.
# So for now, we just add everything to a new Leaf until it
# splits, as we know that will give the right answer
- new_leaf = LeafNode()
+ new_leaf = LeafNode(search_key_func=self._search_key_func)
new_leaf.set_maximum_size(self._maximum_size)
new_leaf._key_width = self._key_width
# A batch_size of 16 was chosen because:
@@ -1133,12 +1135,13 @@
return new_leaf
-def _deserialise(bytes, key):
+def _deserialise(bytes, key, search_key_func):
"""Helper for repositorydetails - convert bytes to a node."""
if bytes.startswith("chkleaf:\n"):
- return LeafNode.deserialise(bytes, key)
+ return LeafNode.deserialise(bytes, key, search_key_func=search_key_func)
elif bytes.startswith("chknode:\n"):
- return InternalNode.deserialise(bytes, key)
+ return InternalNode.deserialise(bytes, key,
+ search_key_func=search_key_func)
else:
raise AssertionError("Unknown node type.")
@@ -1158,7 +1161,9 @@
if pb is not None:
pb.tick()
bytes = record.get_bytes_as('fulltext')
- node = _deserialise(bytes, record.key)
+ # We don't care about search_key_func for this code, because we only
+ # care about external references.
+ node = _deserialise(bytes, record.key, search_key_func=None)
if record.key in uninteresting_keys:
if isinstance(node, InternalNode):
next_uninteresting.update(node.refs())
@@ -1222,7 +1227,9 @@
else:
bytes = adapter.get_bytes(record,
record.get_bytes_as(record.storage_kind))
- node = _deserialise(bytes, record.key)
+ # We don't care about search_key_func for this code, because we
+ # only care about external references.
+ node = _deserialise(bytes, record.key, search_key_func=None)
if isinstance(node, InternalNode):
# uninteresting_prefix_chks.update(node._items.iteritems())
chks = node._items.values()
@@ -1290,7 +1297,9 @@
else:
bytes = adapter.get_bytes(record,
record.get_bytes_as(record.storage_kind))
- node = _deserialise(bytes, record.key)
+ # We don't care about search_key_func for this code, because we
+ # only care about external references.
+ node = _deserialise(bytes, record.key, search_key_func=None)
if isinstance(node, InternalNode):
chks = set(node.refs())
chks.difference_update(all_uninteresting_chks)
=== modified file 'bzrlib/tests/test_chk_map.py'
--- a/bzrlib/tests/test_chk_map.py 2009-01-12 22:55:02 +0000
+++ b/bzrlib/tests/test_chk_map.py 2009-01-21 19:39:56 +0000
@@ -23,7 +23,6 @@
CHKMap,
InternalNode,
LeafNode,
- _deserialise,
)
from bzrlib.tests import TestCaseWithTransport
@@ -891,11 +890,11 @@
ptr2 = nodes[1]
self.assertEqual('k1', ptr1[0])
self.assertEqual('k2', ptr2[0])
- node1 = _deserialise(chkmap._read_bytes(ptr1[1]), ptr1[1])
+ node1 = chk_map._deserialise(chkmap._read_bytes(ptr1[1]), ptr1[1], None)
self.assertIsInstance(node1, LeafNode)
self.assertEqual(1, len(node1))
self.assertEqual({('k1'*50,): 'v1'}, self.to_dict(node1, chkmap._store))
- node2 = _deserialise(chkmap._read_bytes(ptr2[1]), ptr2[1])
+ node2 = chk_map._deserialise(chkmap._read_bytes(ptr2[1]), ptr2[1], None)
self.assertIsInstance(node2, LeafNode)
self.assertEqual(1, len(node2))
self.assertEqual({('k2'*50,): 'v2'}, self.to_dict(node2, chkmap._store))
@@ -1311,7 +1310,7 @@
keys)
# We should be able to access deserialised content.
bytes = self.read_bytes(chk_bytes, keys[1])
- node = _deserialise(bytes, keys[1])
+ node = chk_map._deserialise(bytes, keys[1], None)
self.assertEqual(1, len(node))
self.assertEqual({('foo',): 'bar'}, self.to_dict(node, chk_bytes))
self.assertEqual(3, node._node_width)
More information about the bazaar-commits
mailing list