Python: hash() yields different results for different platforms

  • tim_peters / 200 / Fri, 27 Mar 2009 05:41:00 GMT / Comments (0)
  • [Grant Edwards]

    [Qiangning Hong]
    > Is this relationship (same low 32 bits) guaranteed?


    No. Nothing about hashes is guaranteed, except that when x and y are
    of a hashable type, and x == y, then hash(x) == hash(y) too.

    > Will it change in the future version?


    That's possible, but not planned. Note that the guts of string
    hashing in CPython today is implemented via

    while (--len >= 0)
    x = (1000003*x) ^ *p++;

    where x is C type "long", and the C language doesn't even define what
    that does (behavior when signed multiplication overflows isn't defined
    in C).
  • Keywords:

    hash, yields, different, results, platforms, python

  • http://programming.itags.org/python/32377/«« Last Thread - Next Thread »»