brisbane:CHKMap.iteritems() tweaks
John Arbash Meinel
john at arbash-meinel.com
Tue Mar 24 15:28:08 GMT 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ian Clatworthy wrote:
> John Arbash Meinel wrote:
>> I think I've gotten the fixes I wanted for CHKMap.iteritems(). It is
>> available at:
>>
>> http://bzr.arbash-meinel.com/branches/bzr/brisbane/iter_changes_fixes
>
> Looks good on the whole.
>
>> for length, length_filter in length_filters:
>> - if prefix[:length] in length_filter:
>> - if type(node) == tuple:
>> - keys[node] = prefix
>> - else:
>> - yield node
>> - break
>
> So the previous code broke out of the inner loop on the first match while
> we now continue going so we can collect all matches. I suspect it will
> make very little difference in practice because I'm guessing 90%+ of non-None
> search keys only contain a single tuple anyway?
So for IE.children() yes. We have maybe 30 children, and that quickly
gets spread out across all of the 255-way nodes.
Other places in our code seem to only pass in a single key anyway.
For parent_id,basename access, from what I could see, we only really
look for one directory at a time. So again, 1 entry in the length_filter.
Note that before my change to _iter_nodes, we would have 32 keys at this
point.
>
>> + def test__iter_nodes_splits_key_filter(self):
>> + node = InternalNode('')
>> + child = LeafNode()
>> + child.set_maximum_size(100)
>> + child.map(None, ("foo",), "bar")
>> + node.add_node("f", child)
>> + child = LeafNode()
>> + child.set_maximum_size(100)
>> + child.map(None, ("bar",), "baz")
>> + node.add_node("b", child)
>
> This and the previous test have the same setup code so you
> might want to pull it out into a common method.
>
>> + key_filter = (('foo',), ('bar',), ('cat',))
>> + for child, node_key_filter in node._iter_nodes(None,
>> + key_filter=key_filter):
>> + # each child could only match one key filter, so make sure it was
>> + # properly filtered
>> + self.assertEqual(1, len(node_key_filter))
>
> I don't understand why ('cat',) gives a node_key_length of 1.
> Please explain that in some comments.
>
> Ian C.
('cat',) doesn't give *any* nodes. The point of adding it is to ensure
that it doesn't accidentally end up in one of the other children. (Test
that X hits, but also test that Y *doesn't* hit.)
I'm happy to add some more comments.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAknI/AgACgkQJdeBCYSNAAO3yQCeOqd+GAFB3CGojJQNQf/YeGj9
pCMAnirK/v8tkFAsHUuOhYpVaigGChCf
=Rn7u
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list