[ZODB-Dev] OOTreeSet object retrieval
Torgil Svensson
torgil.svensson at gmail.com
Mon Nov 20 05:04:22 EST 2006
Hi,
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.
More information about the ZODB-Dev
mailing list