[issue34751] Hash collisions for tuples

Tim Peters report at bugs.python.org
Fri Sep 28 00:20:03 EDT 2018


Tim Peters <tim at python.org> added the comment:

Perhaps worth noting that FNV-1a works great if used as _intended_:  on a stream of unsigned bytes.  All tests except the new tuple hash test suffer no collisions; the new test suffers 14.  Nothing is needed to try to worm around nested tuple catastrophes, or to worm around mixing integers of similar magnitude but different signs.  The obvious downside:  on a 64-bit box, it's 8 times as many multiplies :-(  Here's a 64-bit version:

    Py_uhash_t t = (Py_uhash_t)y;
    for (int i = 0; i < sizeof(t); ++i) {
        x = (x ^ (t & 0xff)) * (Py_uhash_t)1099511628211ULL;
        t >>= 8;
    }

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34751>
_______________________________________


More information about the Python-bugs-list mailing list