ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> zodb-dev
zodb-dev
Re: [ZODB-Dev] BTrees and PersistentDict keys: bug or feature
by Casey Duncan other posts by this author
Aug 15 2003 1:25PM messages near this date
Re: [ZODB-Dev] BTrees and PersistentDict keys: bug or feature | Re: [ZODB-Dev] BTrees and PersistentDict keys: bug or feature
On Friday 15 August 2003 12:04 am, Christian Reis wrote:
>  On Thu, Aug 14, 2003 at 11:52:55PM -0400, Casey Duncan wrote:
>  > > To explain a tiny bit further, I'm using an OOBTree that maps
>  > > dictionaries to objects. This is part of the indexing mechanism in
>  > > IndexedCatalog, which is a simple indexing and query mechanism for the
>  > > ZODB. This allows us to do queries like:
>  > > 
>  > >     "5 in mydict"
>  > 
>  > I'm not sure how using dictionaries as keys helps here (it just sounds 
evil to 
>  > me ;^), but this is one place where the Python hashing rules for 
dictionary 
>  
>  I'm suffering from lack of oxygen (hopefully). The important query here
>  is, or course:
>  
>      "mydict == {foo: bar}"
>  
>  -- which is handled correctly (AFAICT, and I can't tell much yet because
>  I still need to test a lot) by simple comparison.

Here are some thoughts, both involving reducing the complexity by converting 
the mutable objects to an immutable representation:

A list and a dict can both be represented in immutable form. The former as a 
tuple and the later as a tuple of key/value pair tuples.

Have you considered converting the values to an immutable form and using that 
as a key? This might have another advantage (or maybe disadvantage), which is 
that all list-like things and all dict-like things would get a LCD 
representation which would compare consistently.

So PersistentMapping({1:2, 2:3}) would become ((1,2),(2,3)) as would {1:2, 
2:3}. Determining what is a mapping could be done with some introspection 
logic (like looking for an "items" method) or by some explicit configuration. 
Now, this would still fall down if the key/values themselves were mutable.

So, in that case I might suggest instead pickling the object and using that as 
a key. Then all the keys would be strings. This would never consider 
PersistentMappings equal to dicts though, but maybe that's what you want. I 
used this technique recently when I needed to use arbitrary types/classes as 
BTree keys.

-Casey

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@[...].org
http://mail.zope.org/mailman/listinfo/zodb-dev
Thread:
Christian Reis
Tim Peters
Christian Reis
Casey Duncan
Christian Reis
Casey Duncan
Christian Reis

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved