[ZODB-Dev] OOTreeSet object retrieval

Dieter Maurer dieter at handshake.de
Mon Nov 20 13:58:51 EST 2006


Torgil Svensson wrote at 2006-11-20 11:04 +0100:
>I have lots of items I want to be able to get by name (string) or loop
>efficiently over all objects. To be able to get all data just by
>iterating the keys i've done a class that is both key and data:
>
>class Item(Persistent):
>    __slots__=['name','attrib1','attrib2']
>    def __init__(self,name,attr1,attr2):
>        Persistent.__init__(self)
>        self.name=name
>        self.attr1=10
>        self.attr2=4
>    def __cmp__(self,other):
>        if type(other)==str:
>            return cmp(self.name,other)
>        return cmp(self.name,other.name)
>    def __hash__(self):
>        return hash(self.name)
>
>My "key" value is a string and this is the large part of the database.
>I also want to reach this from the object.
>
>This will loop efficiently over all data but to get a object using a
>string I must save it in a OOBTree as tree[x]=x . To save db
>creation/update time and some disk-space it would be nice if I can get
>the object reference from a OOTreeSet in this case. Is this possible?
>
>If not, I suggest that __getitem__ should be implemented for the
>OOTreeSet class so performance gains like this is possible.

When I remember right, then Tim Peters once posted a message
that OOBTree keys should not be persistent.

I no longer remember the reasons...



-- 
Dieter


More information about the ZODB-Dev mailing list