Associative Arrays need cleanout method or property to help

Rainer Deyke rainerd at eldwood.com
Sat Mar 20 15:34:10 PDT 2010


On 3/20/2010 13:21, bearophile wrote:
> Moritz Warning:
>> The Python docs say that common usage is mostly about very small
>> aas with frequent accesses but rare changes.
> 
> D and Python will probably have different usage patterns for AAs. In
> Python dicts (AAs) are used to give arguments to functions (that's
> why recursive functions are so slow in Python) and to represent most
> name spaces (there are few exceptions like the __slots__, but they
> are uncommon), so in a big percentage of cases they contain few
> string-value pairs (they have an optimization for string-only keys),
> that's why python dicts have an optimization for less than about 8
> key-value pairs.

I don't know about Java or D, but my usage pattern for
boost::unordered_map in C++ is rather similar to that of Python dicts:
  - Most keys are strings (either std::string or my own interned string
class).
  - The amount of read accesses far exceeds the amount of write
accesses.  Many AAs are write-once, read-often.
  - Small AAs are common, although probably not as common as in Python.
  - I even use boost::unordered_map as the dictionary type in my own
Python-like scripting language.  This accounts for around 10% of my
total usage of boost::unordered_map.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list