How does a Python key store value when a collision occurs?

How does Python store dict key values โ€‹โ€‹when a collision occurs in a hash table? What hash algorithm is used to get the hash value here?

+4
source share
2 answers

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).
+4

: Python , CPython - .

. , -.

0

Source: https://habr.com/ru/post/1525552/


All Articles