Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. int Hash(string str) {
  2.     int hash = 0;
  3.     for(size_t i = 0; str[i] != '\0'; i++)
  4.         hash = hash * 13 + str[i];
  5.     return hash;
  6. }
  7.  
  8. bool Add(T key) {
  9.     size_t j = Hash(key) % this->capacity;
  10.     for(size_t i = 0; i < this->capacity; i++) {
  11.         if (this->Table[j] == NIL || this->Table[j] == DEL) {
  12.             this->Table[j] = key;
  13.             this->size++;
  14.             if (float(this->size) / float(this->capacity) >= MAX_ALPHA) this->grow();
  15.             return true;
  16.         } else if (this->Table[j] == key) return false;
  17.         j = (j + (i + 1)) % this->capacity;
  18.     }
  19.     return false;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement