-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hanno Schlichting wrote: > On Mon, Aug 16, 2010 at 12:14 PM, Pedro Ferreira > <jose.pedro.ferre...@cern.ch> wrote: >> Could this be some problem with using persistent objects as keys in a BTree? >> Some comparison problem? > > I'm not entirely sure about this, but I think using persistent objects > as keys isn't supported. Looking at the code, I doubt using anything > expect simple types like unicode strings or tuples of simple types > will work without further work. > >>From what I can see in the code, BTree's use functions like > PyObject_Compare to compare different keys. Persistent doesn't > implement any special compare function and falls back to the standard > hash algorithm for an object. This happens to be its memory address. > The memory address obviously changes over time and the same address > gets reused for different objects. > > I think implementing a stable hash function for your type could make > this work though. > > The ZODB gods correct me please :)
Btrees require "comparability", rather than "hashability": your persistent type needs to define a total ordering[1], which typically means defining '__cmp__' for your class. You could also define just '__eq__' and '__lt__', but '__cmp__' is slightly more efficient. [1]http://www.zodb.org/documentation/guide/modules.html#total-ordering-and-persistence Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tsea...@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkxpK18ACgkQ+gerLs4ltQ5gIwCfQDXxLwxpWrghFtRF76MBxesS RtcAnA3+yv+6+XfDRkPBBZcZpoqZ6mO0 =ygVN -----END PGP SIGNATURE----- _______________________________________________ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org https://mail.zope.org/mailman/listinfo/zodb-dev