Integer and String Dictionary Keys for Fast Access

Matt Gerrans mgerrans at mindspring.com
Fri Oct 4 02:23:54 EDT 2002


There aren't any pointers in Python (that I know of), just references.

Anyway, I would guess (I haven't looked at the source) the speed of the
dictionary lookup has nothing to do with the fact that variables are
references vs. values; it has more to do with the hashing method.

Maybe GUASS has no hashing at all and just does a string compare to every
key until it finds a match (or maybe something not quite that silly, but
still not particularly good).

My guess is that Python's implementation uses the __hash__() value of
objects (this being one of the fundamental reasons why __hash__() is a
member of the base object, just as Java has the hashCode() method in it's
Object and C++... er... well... uh, forget that analogy), which results in a
quick lookup, unless a particular object overrides and does a poor job of
implementing this method; in particular, since strings are immutable, the
hash only needs to be computed once (not every time it is used), so we would
expect lookups of strings in a hash table to be pretty close to as fast as
lookup of ints.

- m

"Lance" <lbrannma at cablespeed.com> wrote in message
news:upprf95u8f3c9c at corp.supernews.com...
> Yes... I suppose it doesn't matter if everything is a pointer.
> test it out in python, you may be surprised.  I don't think the type
really
> matters for dictionary look ups.






More information about the Python-list mailing list