mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
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.
This commit is contained in:
parent
504239fb38
commit
41bd02256f
3 changed files with 25 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue