[Python-Dev] Decimal <-> float comparisons in py3k.

Mark Dickinson dickinsm at gmail.com
Sat Mar 20 18:05:56 CET 2010


On Sat, Mar 20, 2010 at 3:17 PM, Case Vanhorsen <casevh at gmail.com> wrote:
> On Sat, Mar 20, 2010 at 4:06 AM, Mark Dickinson <dickinsm at gmail.com> wrote:
>> What external modules are there that rely on existing hash behaviour?
>
> I'm only aware of  gmpy and SAGE.
>
>> And exactly what behaviour do they rely on?
>
> Instead of calculating hash(long(mpz)), they calculate hash(mpz)
> directly. It avoids creation of a temporary object that could be quite
> large and is faster than the two-step process. I would need to modify
> the code so that it continues to produce the same result.

Does gmpy only do this for Python 2.6?  Or does it use different
algorithms for 2.4/2.5 and 2.6?  As far as I can tell, there was no
reasonable way to compute long_hash directly at all before the
algorithm was changed for 2.6, unless you imitate exactly what Python
was doing (break up into 15-bit pieces, and do all the rotation and
addition exactly the same way), in which case you might as well be
calling long_hash directly.

Mark


More information about the Python-Dev mailing list