summaryrefslogtreecommitdiff
path: root/Objects/tupleobject.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-06-01 06:36:24 +0000
committerRaymond Hettinger <python@rcn.com>2004-06-01 06:36:24 +0000
commit631e24705dbe174b8eaea5cd21630f370798288f (patch)
treedd52020d866a49a3e37139a1fa2f2f1fd97e4216 /Objects/tupleobject.c
parent767447e5dffcd11ec8cddecfc403de4d2e0439b9 (diff)
downloadcpython-631e24705dbe174b8eaea5cd21630f370798288f.tar.gz
SF bug #942952: Weakness in tuple hash
(Basic approach and test concept by Tim Peters.) * Improved the hash to reduce collisions. * Added the torture test to the test suite.
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r--Objects/tupleobject.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 159dc44fd0..4cb80f0ed5 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -262,15 +262,16 @@ tuplehash(PyTupleObject *v)
register long x, y;
register int len = v->ob_size;
register PyObject **p;
+ long mult = 1000003L;
x = 0x345678L;
p = v->ob_item;
while (--len >= 0) {
y = PyObject_Hash(*p++);
if (y == -1)
return -1;
- x = (1000003*x) ^ y;
+ x = (x ^ y) * mult;
+ mult += 69068L + len + len;
}
- x ^= v->ob_size;
if (x == -1)
x = -2;
return x;