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 Christian Reis other posts by this author
Aug 15 2003 4:04AM 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 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.

>  keys begin to make lots of sense. In Python you are forbidden from using 
>  simple mutable objects as keys since generating a stable hash for them is not 
>  possible unless you subclass and supply your own hash.
>  
>  BTrees make it much easier to shoot yourself in the foot since keys must only 
>  be comparible, which mutable objects usually are. So the thing to note (no 
>  doubt you have realized this) is that when you use mutable objects as BTree 
>  keys (or set members) you are playing with fire and your are very likely to 
>  get burned.

I'm keeping a close eye on this particular feature to see how well this
hack holds out. It may be that we'll just revert to sequential scans and
go on with life.

>  > I've fixed this to make sure I only store dictionaries as keys. My
>  > wrapper class makes sure that the dicts are never mutated while being
>  > used as being keys, and so far check() has been reassuring.
>  
>  Sounds like mongo pain for a "minor feature".
> 
>  hoping-the-bandages-and-grafts-heal-soonly y'rs,

Well, I didn't mention I had to implement this for lists too! 

(And to think all this because nobody on python-dev lets me work on
fixing LC_NUMERIC. I should get a night job.)

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL

_______________________________________________
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