This is called Horner's rule
int hash(string str) {
int h = 0;
for (int i=0; i<str.length - 1 ; i++) {
h = (str[i] + 128*h) % tableSize ;
}
return h ;
}
hash(s) = s1+s2*128+s3*128+s4*128+.....+sn*128
int hash(string str) {
int h = 0;
for (int i=0; i<str.length - 1 ; i++) {
h = (str[i] + 128*h) % tableSize ;
}
return h ;
}
hash(s) = s1+s2*128+s3*128+s4*128+.....+sn*128
No comments:
Post a Comment