I'm really new to HashTables and I'm having a hard time understanding, the process of collision handling, and increasing it's capacity if we run out of space and how does the loadFactor come into play when measuring the available space and capacity? If any code could be provided would really help and appreciated. Side Note: I'm not allowed to use the available class so I have to implement it on my own.
Here's my put method that I override from the interface.
@Override
public String put(String key, String value) {
int i = key.hashCode();
int hash = (i % capacity);
while (table[hash] != null && table[hash].key() != key)
{
if(hash > loadFactor*capacity)
{
capacity = capacity*2;
}
if(hash == TABLE_SIZE)
{
return null;
}
hash = (hash + 1) % capacity;
}
System.out.println("Collision Detected");
String oldKey = table[hash].key();
String oldValue = table[hash].value();
//replace old value with the new
table[hash] = new Entry(key, value);
//return "index " + i + " hash " + hash;
return "Old key: " + oldKey + ", Old Value: " + oldValue;
}