web123456

【C++: Hash】

  • Open hash/hash bucket (chain address method)

  1. Collection of array + linked list                                                                                                                                                                                                                                                                                                                                                �
  2. How to use it?

(1)insert

  • Calculate the bucket number using hash function
  • Creating nodes
  • Header insert into hash bucket

(2) Expand capacity

  • New open space
  • Remove the linked lists in the old bucket one by one, calculate the new bucket number, and insert the header into the new bucket
  • Release the old bucket

(3)find

  • Calculate the bucket number corresponding to the element to be searched through the hash function
  • Detect whether the element is in the linked list of the bucket

(4)earse

  • Check whether the deleted element exists through the find function
  • If it exists, calculate the corresponding bucket number of the element that needs to be deleted through the hash function, find the element and delete it