Since Python hash tables have a size equal to two forces, the least significant bits of the hash value determine the location in the hash table (or at least the location of the original probe).
The sequence of probes in the size of table n is determined as follows:
def gen_probes(hashvalue, n): 'Same sequence of probes used in the current dictionary design' mask = n - 1 PERTURB_SHIFT = 5 if hashvalue < 0: hashvalue = -hashvalue i = hashvalue & mask yield i perturb = hashvalue while True: i = (5 * i + perturb + 1) & 0xFFFFFFFFFFFFFFFF yield i & mask perturb >>= PERTURB_SHIFT
For example, a dictionary:
d = {'timmy': 'red', 'barry': 'green', 'guido': 'blue'}
stored as an array of size 8 with each entry in the form (hash, key, value) :
entries = [['--', '--', '--'], [-8522787127447073495, 'barry', 'green'], ['--', '--', '--'], ['--', '--', '--'], ['--', '--', '--'], [-9092791511155847987, 'timmy', 'red'], ['--', '--', '--'], [-6480567542315338377, 'guido', 'blue']]
The C source code for entering keys in Python dictionaries can be found here: http://hg.python.org/cpython/file/cd87afe18ff8/Objects/dictobject.c#l550