[pypy-svn] r78811 - in pypy/branch/fast-forward/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Nov 7 14:16:00 CET 2010
Author: arigo
Date: Sun Nov 7 14:15:58 2010
New Revision: 78811
Modified:
pypy/branch/fast-forward/pypy/rpython/rint.py
pypy/branch/fast-forward/pypy/rpython/test/test_rint.py
Log:
Test and improvement of hash() of an r_longlong.
Modified: pypy/branch/fast-forward/pypy/rpython/rint.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rpython/rint.py (original)
+++ pypy/branch/fast-forward/pypy/rpython/rint.py Sun Nov 7 14:15:58 2010
@@ -291,6 +291,9 @@
return None
def get_ll_hash_function(self):
+ if (sys.maxint == 2147483647 and
+ self.lowleveltype in (SignedLongLong, UnsignedLongLong)):
+ return ll_hash_long_long
return ll_hash_int
get_ll_fasthash_function = get_ll_hash_function
@@ -411,6 +414,9 @@
def ll_hash_int(n):
return intmask(n)
+def ll_hash_long_long(n):
+ return intmask(intmask(n) + 9 * intmask(n >> 32))
+
def ll_check_chr(n):
if 0 <= n <= 255:
return
Modified: pypy/branch/fast-forward/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rpython/test/test_rint.py (original)
+++ pypy/branch/fast-forward/pypy/rpython/test/test_rint.py Sun Nov 7 14:15:58 2010
@@ -5,6 +5,7 @@
from pypy.rpython.test import snippet
from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
from pypy.rlib.rarithmetic import ovfcheck
+from pypy.rlib import objectmodel
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
if r_longlong is not r_int:
@@ -353,6 +354,18 @@
res = self.interpret(f, [3])
assert res == 3
+ def test_hash(self):
+ def f(x):
+ return objectmodel.compute_hash(x)
+ res = self.interpret(f, [123456789])
+ assert res == 123456789
+ res = self.interpret(f, [int64(123456789012345678)])
+ if sys.maxint == 2147483647:
+ # check the way we compute such a hash so far
+ assert res == -1506741426 + 9 * 28744523
+ else:
+ assert res == 123456789012345678
+
class TestLLtype(BaseTestRint, LLRtypeMixin):
pass
More information about the Pypy-commit
mailing list