durusmail: durus-users: snag with btree.get(key)
snag with btree.get(key)
2005-07-07
2005-07-07
2005-07-07
2005-07-08
2005-07-08
2005-07-08
2005-07-08
2005-07-08
2005-07-11
2005-07-08
2005-07-08
2005-07-08
2005-07-08
Schevo and moellus [was: Re: [Durus-users] snag with btree.get(key)]
2005-07-11
Re: Schevo and moellus [was: Re: [Durus-users] snag with btree.get(key)]
2005-07-13
2005-07-14
2005-07-14
2005-07-14
2005-07-13
2005-07-07
snag with btree.get(key)
Neil Schemenauer
2005-07-07
On Thu, Jul 07, 2005 at 12:24:06PM -0600, Neil Schemenauer wrote:
> You might be getting bitten by the fact that btree keys are
> compared, not hashed.

I thought about this a little more and I believe this is the
problem.  I was initially confused as to why you could get away with
a __hash__ on objects and still use them as keys in a
PersistentDict.  The reason is that although the default __hash__
returns the object's memory address, that works for PersistentDict
because the objects are all loaded at once into the table when the
object is unghosted.  That's not the case for btrees (the default
__cmp__ also uses the memory address).

Something like this would probably work (untested):

    def __cmp__(self, other):
        if self is other:
            return 0
        return cmp(self, other)
reply