[ZODB-Dev] OOBTree: Persistent Objects as keys

Thomas Guettler zopestoller@thomas-guettler.de
Tue, 05 Feb 2002 15:58:22 +0100


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.
>>
>
> 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.
>
If the tree of BTree would use type(obj) at the first level it should work:

BTree
|-strings ["foo", "foo2", ...]
|-FooObjects
|-Integers

Then obj.__cmp__() only compares objects of the same type.

This could fail if a object changes its type. Like a integer becoming a 
long.

thomas