What are prefix hash functions used for? I have created chaining, quadratic, and linear hash tables. I was given simples, prefix, and full-length hash methods which i am not sure what they are used for??
Here is the code:
int HashTable_qp::preHash(string & key, int tableSize )
{
string pad = "AA";
//some words in the input are less than 3 letters
//I choose to pad the string with A because all padded characters
//have same ascii val, which is low, and will hopefully alter the results less
if (key.length() < 3)
{
key.append(pad);
}
return ( key[0] + 27 * key[1] + 729 * key[2] ) % tableSize;
}
collision detection:
while(i != DataArray.size())
{
tStart = clock();
if(QuadraticProbingHT.preHash(DataArray[i],101) == QuadraticProbingHT.preHash(DataArray[i],101) )
{
collision_count++;
}
tStop = clock();
total_c += tStop - tStart;
i++;
}
A prefix hash hashes a string by its first few characters (the prefix).
Note that in the implementation you give, it hashes a string using the first three characters (if existent; it pads with
AAif necessary). Thus,assandassociatehas the same hash value under this specific prefix hash.A full-length hash uses every character in the string to determine the hash value.