This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients alexandre.vassalotti, neologix, pitrou, serhiy.storchaka, tim.peters, vstinner
Date 2014-05-23.08:56:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1400835366.49.0.792389319875.issue21556@psf.upfronthosting.co.za>
In-reply-to
Content
"_Py_hashtable_hash_ptr is quite crude in that it doesn't even try to compensate for pointer alignment, so there will automatically be many collisions. Only one hash bucket every 8 or 16 will be used, at best."

I chose to use _Py_HashPointer() to drop (shift) lower bits. Do you mean that it's not enough? Python memory allocator uses an alignement on 8 bytes (2**3).

Py_uhash_t
_Py_hashtable_hash_ptr(const void *key)
{
    return (Py_uhash_t)_Py_HashPointer((void *)key);
}

Py_hash_t
_Py_HashPointer(void *p)
{
    Py_hash_t x;
    size_t y = (size_t)p;
    /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid
       excessive hash collisions for dicts and sets */
    y = (y >> 4) | (y << (8 * SIZEOF_VOID_P - 4));
    x = (Py_hash_t)y;
    if (x == -1)
        x = -2;
    return x;
}
History
Date User Action Args
2014-05-23 08:56:06vstinnersetrecipients: + vstinner, tim.peters, pitrou, alexandre.vassalotti, neologix, serhiy.storchaka
2014-05-23 08:56:06vstinnersetmessageid: <1400835366.49.0.792389319875.issue21556@psf.upfronthosting.co.za>
2014-05-23 08:56:06vstinnerlinkissue21556 messages
2014-05-23 08:56:04vstinnercreate