Rev 4774: Change the testing layer so that CHKMap is tested using tuples. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple-chk-map
John Arbash Meinel
john at arbash-meinel.com
Wed Oct 21 20:00:10 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple-chk-map
------------------------------------------------------------
revno: 4774
revision-id: john at arbash-meinel.com-20091021185947-zud32qo2zi7xlglt
parent: john at arbash-meinel.com-20091021185008-8t37d9j69t0yo2vg
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-static-tuple-chk-map
timestamp: Wed 2009-10-21 13:59:47 -0500
message:
Change the testing layer so that CHKMap is tested using tuples.
For now, it makes life easier, so go ahead and do it.
Potentially we want to have a debug flag that indicates when tuples are being used.
Because passing in a tuple wastes memory, if we then convert it to a StaticTuple.
The main reason to be type strict is because we want to use StaticTuple as much
internally as we can, and it eases some of the extension writing, since we don't
have to handle packing multiple object types, etc.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py 2009-10-21 18:50:08 +0000
+++ b/bzrlib/chk_map.py 2009-10-21 18:59:47 +0000
@@ -494,6 +494,9 @@
"""Iterate over the entire CHKMap's contents."""
self._ensure_root()
# TODO: StaticTuple Barrier here
+ if key_filter is not None:
+ as_st = StaticTuple.from_sequence
+ key_filter = [as_st(key) for key in key_filter]
return self._root_node.iteritems(self._store, key_filter=key_filter)
def key(self):
=== modified file 'bzrlib/tests/test_chk_map.py'
--- a/bzrlib/tests/test_chk_map.py 2009-10-21 18:50:08 +0000
+++ b/bzrlib/tests/test_chk_map.py 2009-10-21 18:59:47 +0000
@@ -1132,7 +1132,7 @@
def test_iteritems_selected_one_of_two_items(self):
chkmap = self._get_map( {("a",):"content here", ("b",):"more content"})
self.assertEqual({("a",): "content here"},
- self.to_dict(chkmap, [StaticTuple("a",)]))
+ self.to_dict(chkmap, [("a",)]))
def test_iteritems_keys_prefixed_by_2_width_nodes(self):
chkmap = self._get_map(
@@ -1141,7 +1141,7 @@
maximum_size=10, key_width=2)
self.assertEqual(
{("a", "a"): "content here", ("a", "b"): 'more content'},
- self.to_dict(chkmap, [StaticTuple("a",)]))
+ self.to_dict(chkmap, [("a",)]))
def test_iteritems_keys_prefixed_by_2_width_nodes_hashed(self):
search_key_func = chk_map.search_key_registry.get('hash-16-way')
@@ -1157,7 +1157,7 @@
maximum_size=10, key_width=2, search_key_func=search_key_func)
self.assertEqual(
{("a", "a"): "content here", ("a", "b"): 'more content'},
- self.to_dict(chkmap, [StaticTuple("a",)]))
+ self.to_dict(chkmap, [("a",)]))
def test_iteritems_keys_prefixed_by_2_width_one_leaf(self):
chkmap = self._get_map(
@@ -1165,7 +1165,7 @@
("b", ""): 'boring content'}, key_width=2)
self.assertEqual(
{("a", "a"): "content here", ("a", "b"): 'more content'},
- self.to_dict(chkmap, [StaticTuple("a",)]))
+ self.to_dict(chkmap, [("a",)]))
def test___len__empty(self):
chkmap = self._get_map({})
@@ -1380,9 +1380,9 @@
chkmap = chk_map.CHKMap(chk_bytes, None,
search_key_func=chk_map._search_key_16)
chkmap._root_node.set_maximum_size(10)
- chkmap.map(StaticTuple('1',), 'foo')
- chkmap.map(StaticTuple('2',), 'bar')
- chkmap.map(StaticTuple('3',), 'baz')
+ chkmap.map(('1',), 'foo')
+ chkmap.map(('2',), 'bar')
+ chkmap.map(('3',), 'baz')
self.assertEqualDiff("'' InternalNode\n"
" '1' LeafNode\n"
" ('2',) 'bar'\n"
@@ -1396,7 +1396,7 @@
search_key_func=chk_map._search_key_16)
# We can get the values back correctly
self.assertEqual([(('1',), 'foo')],
- list(chkmap.iteritems([StaticTuple('1',)])))
+ list(chkmap.iteritems([('1',)])))
self.assertEqualDiff("'' InternalNode\n"
" '1' LeafNode\n"
" ('2',) 'bar'\n"
@@ -1411,9 +1411,9 @@
chkmap = chk_map.CHKMap(chk_bytes, None,
search_key_func=chk_map._search_key_255)
chkmap._root_node.set_maximum_size(10)
- chkmap.map(StaticTuple('1',), 'foo')
- chkmap.map(StaticTuple('2',), 'bar')
- chkmap.map(StaticTuple('3',), 'baz')
+ chkmap.map(('1',), 'foo')
+ chkmap.map(('2',), 'bar')
+ chkmap.map(('3',), 'baz')
self.assertEqualDiff("'' InternalNode\n"
" '\\x1a' LeafNode\n"
" ('2',) 'bar'\n"
@@ -1427,7 +1427,7 @@
search_key_func=chk_map._search_key_255)
# We can get the values back correctly
self.assertEqual([(('1',), 'foo')],
- list(chkmap.iteritems([StaticTuple('1',)])))
+ list(chkmap.iteritems([('1',)])))
self.assertEqualDiff("'' InternalNode\n"
" '\\x1a' LeafNode\n"
" ('2',) 'bar'\n"
@@ -1888,7 +1888,8 @@
node._items['\xbe'] = None
node.add_node("\x85", leaf2)
self.assertEqual([(('strange',), 'beast')],
- sorted(node.iteritems(None, [StaticTuple('strange',), StaticTuple('weird',)])))
+ sorted(node.iteritems(None, [StaticTuple('strange',),
+ StaticTuple('weird',)])))
def test_iteritems_partial_empty(self):
node = InternalNode()
More information about the bazaar-commits
mailing list