Planning a Python Course for Beginners

Chris Angelico rosuav at gmail.com
Thu Aug 10 16:16:47 EDT 2017


On Fri, Aug 11, 2017 at 6:03 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Peter Otten <__peter__ at web.de>:
>
>> Steve D'Aprano wrote:
>>> The C code says:
>>>
>>>>/* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid
>>>>excessive hash collisions for dicts and sets */
>>>
>>> which I think agrees with my comment: using the id() itself would put
>>> too many objects in the same bucket (i.e. too many collisions).
>>
>> There's a subtle diffence: you expected objects with nearby memory
>> addresses to end up in the same "bucket" while actually all addresses
>> (are likely to) have the same low bits, and creation time does not
>> matter.
>
> I see no point in CPython's rotation magic.

Have you ever implemented a hashtable? The most common way to pick a
bucket for an object is to use modulo on the number of buckets.

ChrisA



More information about the Python-list mailing list