[Tutor] hash value input
Emile van Sebille
emile at fenx.com
Fri Jan 29 17:23:37 CET 2010
On 1/29/2010 5:03 AM spir said...
> 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?
More information about the Tutor