I'm diggin in the dict
structure in Python, and I'm trying to understand the implementation of compact dict with faster iteration explained here [Python-Dev] More compact dictionaries with faster iteration by Raymond Hettinger
In this message, Raymond shows how the current dict implementation is and how it can be more memory efficient. He depict dict structure like this:
d = {'timmy': 'red', 'barry': 'green', 'guido': 'blue'}
is currently stored as:
entries = [['--', '--', '--'],
[-8522787127447073495, 'barry', 'green'],
['--', '--', '--'],
['--', '--', '--'],
['--', '--', '--'],
[-9092791511155847987, 'timmy', 'red'],
['--', '--', '--'],
[-6480567542315338377, 'guido', 'blue']]
Instead, the data should be organized as follows:
indices = [None, 1, None, None, None, 0, None, 2]
entries = [[-9092791511155847987, 'timmy', 'red'],
[-8522787127447073495, 'barry', 'green'],
[-6480567542315338377, 'guido', 'blue']]
My question is how does the new dict implementation performs lookup, if the indices data is numerical 0, 1, 2, as the items were entered? Is it just for clarity, and the actual value is different (eg, hash value of the key) ?
Some references I already looked Dictionaries are ordered in Python 3.6+