brisbane:CHKMap.iteritems() tweaks

Ian Clatworthy ian.clatworthy at internode.on.net
Tue Mar 24 12:38:47 GMT 2009


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?

> +    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.



More information about the bazaar mailing list