This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: guile extension: python dictionary type



jglascoe@jay.giss.nasa.gov writes:
> hello,
> 
> After reading Jim Blandy's "Data Representation in Guile", and having a
> little extra time on my hands, I rewrote Python's dictionary type as a
> Guile extension.  For fun.  
> 
> This dictionary type differs significantly from Guile's hash tables, in
> that the keys must be immutable: symbols, characters, numbers, booleans,
> etc.  Unfortunately, strings are right out (string-set! and friends, you 
> know).  Haven't done any performance tests yet, but I bet it's pretty darn
> fast.
> 
> If anyone's interested in seeing it, LMK.  BTW, the CWI copyright is, of
> course, proudly affixed to the extension code.  In fact, the extension
> type's name is "pydict".  Cool.
> 

Is it preferable to hash tables in any particular way?

Modulo auto-resizing, which Guile hashtables should have anyway but
don't (I secretly plot a reimplementation at some point, personally),
hash tables are supposed to have O(1) access, it's hard to beat that
except by improving the constant.

Actually, I think a Guile hashtable will totally break right now if
you mutate a key. So while they don't require objects to be immutable,
they will give incorrect semantics if you do mutate the object. Still,
it is very useful to hash by string or list keys.


 - Maciej Stachowiak