hashkey/digest for a complex object

Hrvoje Niksic hniksic at xemacs.org
Sun Oct 10 10:51:14 CEST 2010

Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:

> On Sat, 09 Oct 2010 21:39:51 +0100, Arnaud Delobelle wrote:
>> 1. hash() is an idempotent function, i.e. hash(hash(x)) == hash(x) hold
>> for any hashable x (this is a simple consequence of the fact that
>> hash(x) == x for any int x (by 'int' I mean 2.X int)).
> It's a beautiful theory, but, alas, it is not the case.
>>>> hash(-1) == -1
> False

This is a counter-example for the (invalid) premise that hash(x) == x,
but not for the invariant of hash(hash(x)) == hash(x).

>>> hash(hash(-1)) == hash(-1)
>>> hash(hash(2**64)) == hash(2**64)

> Aside: what do you mean by '2.x int'? Do you mean an int in 2.x versions 
> before, or after, ints and longs were partially integrated?

I would take it to mean the type 2.x calls 'int', i.e. fixed-width
integer type.

More information about the Python-list mailing list