[Tutor] object representation

spir denis.spir at gmail.com
Thu Mar 4 08:47:04 CET 2010


Hello,

In python like in most languages, I guess, objects (at least composite ones -- I don't know about ints, for instance -- someone knows?) are internally represented as associative arrays. Python associative arrays are dicts, which in turn are implemented as hash tables. Correct?
Does this mean that the associative arrays representing objects are implemented like python dicts, thus hash tables?

I was wondering about the question because I guess the constraints are quite different:
* Dict keys are of any type, including heterogeneous (mixed). Object keys are names, ie a subset of strings.
* Object keys are very stable, typically they hardly change; usually only values change. Dicts often are created empty and fed in a loop.
* Objects are small mappings: entries are explicitely written in code (*). Dicts can be of any size, only limited by memory; they are often fed by computation.
* In addition, dict keys can be variables, while object keys rarely are: they are literal constants (*).

So, I guess the best implementations for objects and dicts may be quite different. i wonder about alternatives for objects, in particuliar trie and variants: http://en.wikipedia.org/wiki/Trie, because they are specialised for associative arrays which keys are strings.

denis

PS: Would someone point me to typical hash funcs for string keys, and the one used in python?

(*) Except for rare cases using setattr(obj,k,v) or obj.__dict__[k]=v.
-- 
________________________________

la vita e estrany

spir.wikidot.com



More information about the Tutor mailing list