In the code given, it was trying to give a valid index for a hashtable by checking for any collision using another method linearprobe. I am just confuse of why we need to check for index < 0, so will there be instance when hashCode will be negative? When/why will that happens?
private int getHashIndex(K key)
{
//1.convert key to hashcode, then get the index;
//2. then use linear probing to check for the correct index;
int index = key.hashCode() % hashTable.length;
if(index < 0) { //So a hash code can be negative?
index += hashTable.length;
}
index = linearProbe(index,key);
return index;
}