Planning a Python Course for Beginners

Marko Rauhamaa marko at pacujo.net
Thu Aug 10 16:56:11 EDT 2017


Chris Angelico <rosuav at gmail.com>:

> On Fri, Aug 11, 2017 at 6:03 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> 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.

Like I said earlier, CPython takes the __hash__() value and scrambles
it. Look for "perturb" in:

  <URL: https://github.com/python/cpython/blob/master/Objects/dictobject.c>

>From a comment:

   Now the probe sequence depends (eventually) on every bit in the hash
   code, and the pseudo-scrambling property of recurring on 5*j+1 is
   more valuable, because it quickly magnifies small differences in the
   bits that didn't affect the initial index.


Marko



More information about the Python-list mailing list