diff options
author | Raymond Hettinger <python@rcn.com> | 2004-06-01 06:36:24 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-06-01 06:36:24 (GMT) |
commit | 41bd02256f5a2348d2de3d6e5fdfcaeb2fcaaebc (patch) | |
tree | 7c27849dbc8f686cde8f37f55002ed4b13255107 /Objects/tupleobject.c | |
parent | 504239fb38da8526bb48cf8b0778fe47e34554e5 (diff) | |
download | cpython-41bd02256f5a2348d2de3d6e5fdfcaeb2fcaaebc.zip cpython-41bd02256f5a2348d2de3d6e5fdfcaeb2fcaaebc.tar.gz cpython-41bd02256f5a2348d2de3d6e5fdfcaeb2fcaaebc.tar.bz2 |
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.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 159dc44..4cb80f0 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; |