Which is the true DJB hash function?
How do you think about them?
I got it from:
//http://cboard.cprogramming.com/showthread.php?t=109269&highlight=hash
and http://codesnippets.joyent.com/user/...tag/algorithms
Code:Hash hashf(char *string) { char *p = string; Hash hash = 5381; while(*p != 0) { hash = ((hash << 5) + hash) + *(p++); } return hash & 0x7FFFFFFF; }
This one I got from Wikipedia, http://www.flipcode.com/archives/HashString.shtml, http://www.partow.net/programming/hashfunctions/
Second question:Code:Hash hashf(char *string) { char *p = string; Hash hash = 5381; while(*p != 0) { hash = ((hash << 5) + hash) + *(p++); } return hash; }
I don't think we need to copy the passed pointer, because this one works.Code:Hash hashf(char *string) { char *p = string; //Do we need to copy this one? Hash hash = 5381; while(*p != 0) { hash = ((hash << 5) + hash) + *(p++); } return hash; }
Thanks in advance.Code:Hash hashf(char *s) { Hash hash = 5381; while(*s != 0) { hash = ((hash << 5) + hash) + *(s++); } return hash & 0x7FFFFFFF; }