Is 100,000 entries big for a dictionary?

Tim Peters tim.one at home.com
Sun Dec 31 18:54:16 EST 2000


[rturpin at my-deja.com]
> Thank you for the comments. I assume it does the usual
> extensible hashing mechanism, extending the hash value
> by one bit, and the table by a factor of two, when it
> is time to grow?

On most machines hash values are 32 bits, and are always computed as such,
and are cached in the dict entry.  When it's time to grow, the table does
double in size, but hash values are not recomputed -- it simply uses one
more of the hash bits that's always been there.  Note that entries are
reinserted when the table grows -- that's probably not what you meant by
"the usual extensible hashing mechanism".  A table may also shrink.

> I'm glad to read that it uses open probing. I think this makes
> more sense for tables that reside in memory, and that have no
> strong granularity.

So did Guido <wink>.

>> if-you-do-have-frequent-collisions-i'll-consider-it-a-bug-ly y'rs

> What hash function does it use?

Each type defines its own hash method (and your classes can too, by
supplying a __hash__ method), so, sorry, there's no succinct way to answer
that (the tuple hash is not the string hash is not the int hash etc).  Note
that Python dicts use equality, not object identity, so there are some odd
constraints on hash functions; for example, it must be that hash(42) ==
hash(42L) == hash(42.0) == hash(complex(42)).

it's-almost-time-for-you-to-read-the-source-code<0.9-wink>-ly
    y'rs  - tim





More information about the Python-list mailing list