F
flipdog
Hello all,
I didn't know there is a thread on hash function started in this newsgroup
so reposted my posting from another group.
Hope I can have some feedbacks. I am new to hash table.
I came across a very well presented tutorial web page wrt hash table. In
its content, it listed a number of hash functions which the web master(?)
quoted from other web sites. So no explainations for these hash functions
and I failed to understand a couple of them. They are quite similar so I
ask help for one. Wonder if someone can shed some light for me?
/*Peter Weinberger's*/
int hashpjw(char *s)
{
char *p;
unsigned int h,g;
h=0;
for (p=s; *p != '\0'; p++)
{
h = (h<<4) + *p;
if (g = h & 0xF0000000)
{
h ^= g>>24;
h ^= g;
}
}
return h%211;
}
Within the for loop, what exactly does the second line do? Bit shifting by
4 units and added to the particular char entry of the string?
The third line in the for loop, what is the purpose of bitwise and h and
0xF0000000? Why 0xF0000000 in the first place?
I failed to understand the logic of the next two lines within the
conditional statement as well?
Thanks in advance,
FD
I didn't know there is a thread on hash function started in this newsgroup
so reposted my posting from another group.
Hope I can have some feedbacks. I am new to hash table.
I came across a very well presented tutorial web page wrt hash table. In
its content, it listed a number of hash functions which the web master(?)
quoted from other web sites. So no explainations for these hash functions
and I failed to understand a couple of them. They are quite similar so I
ask help for one. Wonder if someone can shed some light for me?
/*Peter Weinberger's*/
int hashpjw(char *s)
{
char *p;
unsigned int h,g;
h=0;
for (p=s; *p != '\0'; p++)
{
h = (h<<4) + *p;
if (g = h & 0xF0000000)
{
h ^= g>>24;
h ^= g;
}
}
return h%211;
}
Within the for loop, what exactly does the second line do? Bit shifting by
4 units and added to the particular char entry of the string?
The third line in the for loop, what is the purpose of bitwise and h and
0xF0000000? Why 0xF0000000 in the first place?
I failed to understand the logic of the next two lines within the
conditional statement as well?
Thanks in advance,
FD