[ZODB-Dev] OOBTree: Persistent Objects as keys

Jim Fulton jim@zope.com
Wed, 06 Feb 2002 07:27:05 -0500


Toby Dickenson wrote:
> 
> On Tuesday 05 February 2002 1:56 pm, Thomas Guettler wrote:
> >Toby Dickenson wrote:
> >>On Tue, 05 Feb 2002 10:46:52 +0100, Thomas Guettler
> >>
> >><zopestoller@thomas-guettler.de> wrote:
> >>> I have a strange problem with persistent objects as keys
> >>>The __hash__ function of my class:
> >>
> >>Are you sure its getting called? by the BTree?
> >>
> >>BTrees store keys using their sort order, not hash value. I guess you
> >>have not defined a __cmp__ ?
> >
> >Thank you Toby. Unfortunately I have different types of objects as keys.
> >I think this won't be
> >that easy. I think it is not that easy to compare strings and different
> >kind of objects with each other.

Many comparisons accross types are meaningful, as you point out in a
later
post.
 
> Indeed.
> 
> You are not alone with this proble; Zope makes the same mistake since it uses
> keys of different types in ZCatalog Indexes. The symptom of the problem, as
> you describe, is keys myseriously disappearing.
> 
> Im not aware of any good solution.
> 
> :-(

The problem occurs when Python falls back to comparing addresses.
If we could raise an error when this happens, we could avoid building
meaningless BTrees. (Note that a similar problem occurs when hashes
based
on addresses of persistenct objects are uses in has tables.)

Hm, maybe BTrees should use their own comparison algorithm
that never compares addresses. This would be a bit of a pain, since
given the complexity of Python's internal comparison logic. Perhaps
the Python logic could just be copied and the bit that falls back to
address comparison could be hacked out.

Jim