On Jun 7, 2010, at 6:12 AM, Florent Hivert wrote:
Hi there,
I've question concerning handling of hash value vs portability. Is
sage
developer guide manual one can read:
Here is the definition of __hash__ from the Python reference
manual.
Called for the key object for dictionary operations, and by the
built-in function hash(). Should return a 32-bit integer
usable as a
hash value for dictionary operations.
However with ipython (on a 64 bits machine):
In [1]: hash(None)
Out[1]: 140504985179472
which definitely does looks like a 32 bit value. Moreover, it seem
that in
python ref man, [2], the sentence about 32-bits has been removed. So
I have
two questions:
1. I think we should update the devguide, or is there something I
don't get ?
No, we should update the developers guide. Despite this sentence, the
(c) return type of "hash" has been a long since Python 2.3 at least,
so I think this wasn't ever correct for 64-bit long machines. (What
was required is that it fit into a Python int.)
2. I'm writing a Cython class which caches the hash value. Which
type should I
use for the attribute ? int doesn't work since when trying to
store the
hash of None in an int I get
OverflowError: value too large to convert to int
Is long ok and portable (it is was is used in a few place in
sage) ? Should
we write it in the doc ?
Yes, we should be using C longs here. Under the hood
Python int = C long != C int
Python float = C double != C float
and Python longs have no (native) C equivalent.
- Robert
--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org