Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. VALUE& operator[](const KEY& key) {
  2.     size_t index = _hash(key) % _table.size();
  3.     LIST& list = _table[index];
  4.  
  5.     for (auto iter = list.begin(); iter != list.end(); ++iter) {
  6.         if (iter->first == key) {
  7.             return iter->second;
  8.         }
  9.     }
  10.  
  11.     _size++;
  12.     if (double(_size) / _table.size() > max_coef) {
  13.         this->rehash(_table.size() * size_t(max_coef));
  14.  
  15.         LIST& new_list = _table[_hash(key) % _table.size()];
  16.         new_list.push_back(PAIR(key, VALUE()));
  17.         return new_list.back().second;
  18.     }
  19.  
  20.     list.push_back(PAIR(key, VALUE()));
  21.  
  22.     return list.back().second;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement