1.PyDictEntry Data structure
typedef struct { 2 /* Cached hash code of ME_ Key. Note that hash codes is C longs. 3 * We have the use py_ssize_t instead because dict _popitem () Abuses 4 * Me_hash to hold a sear CH finger. 5 */ Py _ssize_t Me_hash; 7 pyobject *me_key; 8 pyobject *me_value; 9 } pydictentry;
2._dictobject data structure
1 typedef struct _DICTOBJECT pydictobject;2 struct _dictobject {3 Pyobject_head4py_ssize_t Ma_fill; /*#Active + # Dummy * /5py_ssize_t ma_used; /*#Active * /6 7/* The table contains Ma_mask + 1 slots, andThat's a power of 2.8* We Store The mask instead of the size because the mask is More9*frequently needed.Ten*/ One py_ssize_t Ma_mask; A -/* ma_table points to ma_smalltable forSmall tables,Else to -* Additional malloc'Ed memory. Ma_table is never null! This rule the* Saves repeated runtime null-testsinchThe Workhorse GetItem and -*SetItem calls. -*/ -Pydictentry *ma_table; +Pydictentry * (*ma_lookup) (Pydictobject *mp, Pyobject *key, long hash); - pydictentry ma_smalltable[pydict_minsize]; +};
You can see that the dict uses a hash data structure!
Python's DICT data structure