hash
// From string to int (complex version)
int hashfunc(String key) {
return md5(key) % hash_table_size
// md5 algorithm is a widely used hash function producing a 128-bit hash value.
}
// easy version
int hashfunc(String key) {
int sum = 0;
for (int i = 0; i< key.length(); i++) {
sum = sum * 33 + (int)(key.charAt(i));
// 33 is generated from experiments. It create less hash conflict.
sum = sum % HASH_TABLE_SIZE;
}
return sum;
}