[ZODB-Dev] RE: __hash__ methods for OOBTrees

Tim Peters tim@zope.com
Thu, 25 Jul 2002 18:32:26 -0400


[Neil Schemenauer]
> Is it safe to have the __hash__ method of a key object to return
> id(self)?  I'm pretty sure it works for dictionaries or
> PersistentMappings but I don't know about BTrees.

BTrees are organized via a total ordering on keys, and don't use __hash__ at
all.  Note that this makes BTree storage dubious for keys of types that
don't implement a consistent __cmp__!  If on OOBTree end up comparing by
object address (which is the default for instances of user-defined classes
if the class doesn't define something better), the results are unpredictable
if you try to reuse the BTree across a pickle-unpickle boundary.