I am not able to figure out how to write the djb3 hashing function on C.
I searched the internet but I found it may be in C++...
unsigned long hash(unsigned char *str){
unsigned long hash = 5381;
int c;
while (c = *str++)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
and if you can explain this to me I will be really thankful...
<<
means shift left (in this context).hash << 5
is the same ashash * 32
only more efficient. Most compilers will do that optimization automatically but not necessarily forhash * 33
as is called for here.