[Tutor] hash value input
spir
denis.spir at free.fr
Fri Jan 29 14:03:22 CET 2010
Hello,
What actually is hashed when a data item is used a dict key? If possible, I would also like some clues on the method used to produce the hash value. (Maybe a pointer to the the relevant part of the python source, if clear and/or commented.)
The reason why I ask is the well known limitation for dict keys to be immutable data (same for sets, indeed). This seems to imply that the value itself is used as source for the hash func. Or am I wrong on this?
I recently discovered that Lua uses the data's address (read: id) as input to the hash func. This allows Lua tables (a kind of more versatile associative array) to use _anything_ as key, since the id is guaranteed not to change, per definition.
[Aside this consideration, hashing addresses ensures a constant type as input (so allows a specific efficient hash method) and the simplest possible one.]
So, how does python do this?
Denis
________________________________
la vita e estrany
http://spir.wikidot.com/
More information about the Tutor
mailing list