public V put(int key, V value) { // Makes sure the key is not already in the hashtable. Entry<V>[] tab = table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry<V> e = tab[index]; e != null; e = e.next) { if (e.hash == hash) { V old = e.value; e.value = value; return old; } } if (count >= threshold) { // Rehash the table if the threshold is exceeded rehash(); tab = table; index = (hash & 0x7FFFFFFF) % tab.length; } // Creates the new entry. Entry<V> e = new Entry<V>(hash, key, value, tab[index]); tab[index] = e; count++; return null; }
public V put(int key, V value) { // Makes sure the key is not already in the hashtable. Entry<V>[] tab = table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry<V> e = tab[index]; e != null; e = e.next) { if (e.hash == hash) { V old = e.value; e.value = value; return old; } } if (count >= threshold) { // Rehash the table if the threshold is exceeded rehash(); tab = table; index = (hash & 0x7FFFFFFF) % tab.length; } // Creates the new entry. Entry<V> e = new Entry<V>(hash, key, value, tab[index]); tab[index] = e; count++; return null; }
public V put(int key, V value) { // Makes sure the key is not already in the hashtable. Entry<V>[] tab = table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry<V> e = tab[index]; e != null; e = e.next) { if (e.hash == hash) { V old = e.value; e.value = value; return old; } } if (count >= threshold) { // Rehash the table if the threshold is exceeded rehash(); tab = table; index = (hash & 0x7FFFFFFF) % tab.length; } // Creates the new entry. Entry<V> e = new Entry<V>(hash, key, value, tab[index]); tab[index] = e; count++; return null; }
public V put(int key, V value) { // Makes sure the key is not already in the hashtable. Entry<V>[] tab = table; int hash = key; int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry<V> e = tab[index]; e != null; e = e.next) { if (e.hash == hash) { V old = e.value; e.value = value; return old; } } if (count >= threshold) { // Rehash the table if the threshold is exceeded rehash(); tab = table; index = (hash & 0x7FFFFFFF) % tab.length; } // Creates the new entry. Entry<V> e = new Entry<V>(hash, key, value, tab[index]); tab[index] = e; count++; return null; }