This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients
Date 2007-08-12.17:57:46
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Doesn't using hash(D.as_tuple()) break the principle that if two objects compare equal then they should have equal hash?

An alternative to converting to long before hashing is to use the fact that for the current hash implementation for long we have
hash(n) == hash(n % (2**32-1)) (except when n is a multiple of 2**32-1).  For a Decimal d that's integral, one should be
able to compute d % (2**32-1) very quickly: if d = c*10**e then just use (c * pow(10, e, 2**32-1)) % (2**32-1), which should be acceptably fast even when d = 123456789E999999999999999.

The only tricky bit is that on a 64-bit system all those 2**32-1 need to be replaced by 2**64-1.  Though now I come to think of it,
since 2**32-1 is a factor of 2**64-1 it would be enough just to do everything modulo 2**64-1 even on a 32-bit system.
History
Date User Action Args
2007-08-23 14:59:07adminlinkissue1770416 messages
2007-08-23 14:59:07admincreate