title: HashTable implementation using chained objects
body: <p>I have this implementation for inserting into a hashtable that uses sequential chaining:</p>
  <pre><code>public void insert(String word, Definition definition) {
  
         int hash = hashFunction(word);
         
  
          if (table[hash] == null) {           
              EntryImplSub chainedEntry = new EntryImplSub(null);
              chainedEntry.addDefinition(definition);
              chainedEntry.setWord(word);
              
              table[hash] = chainedEntry;
              numProbes++;
              entries++;
  
          } 
          
          else{
              
              EntryImplSub chainedEntry = new EntryImplSub(table[hash]);
              chainedEntry.addDefinition(definition);
              chainedEntry.setWord(word);
    
              table[hash] = chainedEntry;
              numProbes++;
              }
              
        }
  </code></pre>
  <p>Essentially, I am trying to make a dictionary. There is an EntryImpl class that acts as an entry object, and each entry has a word and definition (or multiple definitions). Now I have made a new extended class EntryImplSub that is meant to be chained. This new class has a getNext() method and inherits all the other functionality from the normal EntryImpl class. The EntryImplSub constructor is used to set next.</p>
  <h2>Question</h2>
  <p>However this is not working. When I load in a large number of words they are not all entered. And I am not sure why.</p>
  <h2>My Attempt</h2>
  <p>My logic with this implementation is that if the table entry is null, we insert a new EntryImplSub object with next = null, and then set the word and definition.</p>
  <p>If however there is already a word at the position we are trying to insert into, then we must add our new entry to the front of the list. So we create a new EntryImplSub object with the next attribute being set to whatever was already in the table. Then I set the word for the new EntryImplSub and insert this into the table. So we should have a linked list of EntryImplSub.</p>
  <p>I am really not sure why this inst working. I've spent hours trying to find an error, and any help would be appreciated. Let me know if you need clarification on anything.</p>
  <p>Thanks a lot!</p>
  <h2>EDIT</h2>
  <p>Here is the code that checks if an entry is in the table</p>
  <pre><code> public List&lt;Definition&gt; getDefinitions(String word) {
  
      int hash = hashFunction(word);
      //ChainedEntry head = table[hash];
      while (table[hash] != null) {
          numSearches++;
  
          if (((EntryImpl) table[hash]).getWord().equals(word)) {
              return ((EntryImpl) table[hash]).getDefinitions();
          }
          table[hash] = table[hash].getNext();
      }
  
      return null;
  }
  </code></pre>
  <p>If this returns null, then the word is not in the table</p>