Message32607
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. |
|
Date |
User |
Action |
Args |
2007-08-23 14:59:07 | admin | link | issue1770416 messages |
2007-08-23 14:59:07 | admin | create | |
|