title: Implementing resize of a hash table in C++
body: <p>I'm having trouble implementing the resize or expand capacity function in c++. Here's my resize(expandCapacity) function:</p>
  
  <pre><code>    template &lt;typename K, typename V&gt; void HashTable&lt;K, V&gt;::expandCapacity() {
      LinearDictionary&lt;K,V&gt;* temp = this-&gt;hashTable;
      this-&gt;capacity *= 2;
      this-&gt;hashTable = new LinearDictionary&lt;K,V&gt;[this-&gt;capacity];
      for(int i = 0; i &lt; capacity; i++){
        vector&lt;pair&lt;K,V&gt;&gt; items = temp[i].getItems();
        for(int j = 0;j &lt; temp[i].getSize(); i++){
          K key = items[j].first;
          V value = items[j].second;
          int bucket = hash(key, capacity);
          this-&gt;hashTable[bucket].insert(key, value);
        }
      }
      delete temp;
  }
  </code></pre>
  
  <p>and here's my insert function:</p>
  
  <pre><code>    template &lt;typename K, typename V&gt; void HashTable&lt;K, V&gt;::insert(K key, V value) {
      int bucket = hash(key, capacity);
      if(this-&gt;hashTable[bucket].contains(key)){
          throw runtime_error("This key already exists");
        }
      this-&gt;hashTable[bucket].insert(key,value);
      size+=1;
      float loadFactor = (float)(size)/(float)(capacity);
      if(loadFactor &gt;= maxLoadFactor){
        this-&gt;expandCapacity();
      }
     }
  </code></pre>
  
  <p>The template K is for key and V is for value. The hash table is implemented as a pointer to an array of linear dictionaries (a class I implemented myself that is essentially a list of key value pairs, that has some additional useful functions for dictionaries). But this doesn't seem to expand the capacity. Instead I keep getting an error "key already exists" - which is a runtime error implemented by my professor.</p>