Hashing algorithm is very important in CS, for example, the fastest search is key-indexed search, you can locate the target quickly by an address of an array. But, how can we propagate out the indexes? Hashing, it's effective. You can compute the hash code through hash function with a certain range; other else, the hashing algorithm is applied to many other fields, such as encryption, signature, encoding, etc..
Following is very simple hash function for get the key for a string input:
int hash(char *str, int range) {
int h = 0;
int a = 127;
for(; *str != '\0'; str++) {
h = (a*h + *str) % range;
}
return h;
}
Subscribe to:
Post Comments (Atom)
2 comments:
这么说,你从此以后就用这个BLOG了啊,真是的,换什么换啊,我本来就笨,很难找的啊!
yes, I won't move my blog more.
Post a Comment