[ZODB-Dev] OOBTree: Persistent Objects as keys

Jim Fulton [email protected]
Tue, 19 Feb 2002 12:39:46 -0500


Toby Dickenson wrote:
> 
> On Mon, 11 Feb 2002 16:00:52 -0500, Jim Fulton <[email protected]> wrote:
> 
> >> Your proposed
> >> comparison function would raise an exception when comparing 1.0 and "hello",
> >> right?
> >
> >Right.
> >
> >> That sounds good.
> >
> >OK, I'll get some help from the PythonLabs dudes on this.
> 
> Below is a script which demonstrates the unicode problem. It needs the
> BTree exception patch from http://collector.zope.org/Zope/231

Thanks. This is an interesting demonstration.

> Its unpleasant, but I think the only safe option is for Jim's proposed
> new comparison function (for Object-keyed BTrees)

BTW, my proposed comparison function proposal doesn't work, as
Tim Peters explained to me the other day. :(
The problem is that explicit comparison functions, which my
proposal relies on, typically call cmp or comparison operators
themselves. These functions will call the standard comparisons, 
not the special one. Waaaaa.

My thought is to define a new protocol for doing strict ordering.
Then there would be strict BTrees that use this new protocol rather
that comparison. There would also be a registry for registering handlers
for standard types.  Objects used as keys in strict BTrees would
have to implement this protocol or have registered handlers that
implement it.

> to always raise an
> exception if either of its two parameters are unicode (but not if they
> are both unicode).
> 
> Is that reasonable?

Maybe. I guess so. I suspect that to make this workable, you'd
need to convert all text to Unicode if there was a possibility of
getting any unicode.

Jim


--
Jim Fulton           mailto:[email protected]       Python Powered!        
CTO                  (888) 344-4332            http://www.python.org  
Zope Corporation     http://www.zope.com       http://www.zope.org