Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Hash(string str) {
- int hash = 0;
- for(size_t i = 0; str[i] != '\0'; i++)
- hash = hash * 13 + str[i];
- return hash;
- }
- bool Add(T key) {
- size_t j = Hash(key) % this->capacity;
- for(size_t i = 0; i < this->capacity; i++) {
- if (this->Table[j] == NIL || this->Table[j] == DEL) {
- this->Table[j] = key;
- this->size++;
- if (float(this->size) / float(this->capacity) >= MAX_ALPHA) this->grow();
- return true;
- } else if (this->Table[j] == key) return false;
- j = (j + (i + 1)) % this->capacity;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement