I am implementing a hash table with quadratic exploration method. My question is regarding the 0 position of the vector used for table implementation. Here is the code below:
public boolean inserir(Pessoa item) {
int valorHash = hash(item.getCelular());
int contador = 1;
int inicialHash = valorHash;
while(bancoDados[valorHash] != null && !(bancoDados[valorHash].getCelular().equals(-1))) {
valorHash += (contador*contador);
contador++;
valorHash %= tamanhoMax;
}
bancoDados[valorHash] = item;
return true;
}
Through this method position 0 will never be found for an insert. Should I ignore this position in the vector and work with the remainder or is there any way to make my hash value ( valorHash
) arrive at position 0?
NOTE: I use a person's cell number to generate valorHash
in another method. When a person is removed from my table I replace them with someone else, but with an invalid cell number (-1), to indicate that position is available.