New submission from Jeroen Demeyer <j.deme...@ugent.be>:
It's not hard to come up with a hash collision for tuples: >>> hash( (1,0,0) ) 2528505496374819208 >>> hash( (1,-2,-2) ) 2528505496374819208 The underlying reason is that the hashing code mixes ^ and *. This can create collisions because, for odd x, we have x ^ (-2) == -x and this minus operation commutes with multiplication. This can be fixed by replacing ^ with +. On top of that, the hashing code for tuples looks needlessly complicated. A simple Bernstein hash suffices. ---------- messages: 325870 nosy: jdemeyer priority: normal severity: normal status: open title: Hash collisions for tuples _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34751> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com