hash values and equality

Ian Kelly ian.g.kelly at gmail.com
Fri May 20 13:59:44 EDT 2011


On Fri, May 20, 2011 at 10:36 AM, Chris Kaynor <ckaynor at zindagigames.com> wrote:
> I think the question was: can this dummy code ever produce a set containing
> less then itemCount items (for 0 < itemCount < 2**32)?

In CPython, no.  Even when you get a hash collision, the code checks
to see whether the hashes are actually equal before it calls the rich
comparison, the former check being a much faster operation since the
hash values are cached.

I'm not sure whether this can be counted on for all Python
implementations, though.



More information about the Python-list mailing list