[ZODB-Dev] IIBTree.multiunion and list comprehensions

Christian Robottom Reis kiko at async.com.br
Wed Dec 10 06:46:04 EST 2003


On Tue, Dec 09, 2003 at 11:37:03PM -0500, Casey Duncan wrote:
> >     multiunion(tree.keys())
> 
> The *keys* of the tree are sets? Huh?

You *know* I meant tree.values() <wink>

> > takes about the same time to run as
> > 
> >     [value for set in tree.keys() for value in set] (*)
> 
> So you create a set out of this get the unique members?

Actually, all I want is a sequence of values -- it could be a set or a
list.

What I'm doing is collating all the values in all the sets in my BTree.
This BTree holds as values IITreeSets containing a number of integer
OIDs. When I want to pick up *all* the values in the BTree, I need to
join all these IITreeSets together and produce one big set. The fact
that it's unique doesn't really matter in my case given that any given
OID appears only once [as a value].

> > Note that multiunion returns an IISet(), while the latter returns a
> > list; converting between is pretty cheap given the context.
> 
> Note that creating IITreeSets is often fastest because it allocates
> new buckets as it grows rather than resizing a single memory block. An
> IISet is essentially just a sorted C array of unique ints.

IIRC, IITreeSets also have the advantage of "unghosting as you go",
whereas IISets are unpersisted completely when accessing one of its
items. I'm wondering why multiunion creates IISets instead of
IITreeSets, though.

Take care,
--
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 261 2331



More information about the ZODB-Dev mailing list