For โnormalโ Python, this excellent entry from Praveen Gollakota explains this very well, here are the important bits:
- Python dictionaries are implemented as hash tables. Hash tables are made up of slots, and keys are mapped to slots using a hash function.
- - -, .. -, .
- Python dict - (. dictobject.c: 296-297).
- - ( ).
- - - (, ,
O(1) ). - - . .
- -
<hash, key, value>. C (. dictobject.h: 51-56). - dict, 8 . (. dictobject.h: 49)
- ,
i, . CPython i = hash(key) & mask, mask = PyDictMINSIZE - 1, . , i, , . - , ( ,
<hash|key|value>). , !? , , (-!) - , CPython ( PyPy) ( == ) , (dictobject.c 337,344-345). , , , , . , .
- , , . ,
i+1, i+2,... ( ). , (. dictobject.c: 33-126), CPython . . . , , (. dictobject.c: 33-126 ). , , . - ,
i ( i ). , , . , . - , , (. dictobject.h: 64-65).