[Python-ideas] Ordered storage of keyword arguments

spir denis.spir at gmail.com
Thu Oct 28 11:19:36 CEST 2010

On Thu, 28 Oct 2010 10:13:09 +0200
"M.-A. Lemburg" <mal at egenix.com> wrote:

> Ordered dicts are a lot slower than normal dictionaries. I don't
> think that we can make such a change unless we want to make
> Python a lot slower at the same time.

Ruby has ordered hashes since 1.9 with apparently no relevant performance loss -- actually there was gain of performance due to improvement in other aspects of the language. See eg http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ 
I have no idea how python dicts are implemented, especially how entries are held in "buckets". The trick for Ruby is that buckets are actually linked lists, entries are list nodes with pointers allowing linear search inside the bucket. To preserve insertion order, all what is needed is to add parallel pointers to each node representing a parallel list, namely insertion order. Iteration just follows this second sequence of pointers. (I find this solution rather elegant.)

-- -- -- -- -- -- --
vit esse estrany ☣


More information about the Python-ideas mailing list