Skip to content

Instantly share code, notes, and snippets.

@MohamedTaha98
Created October 5, 2017 22:06
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MohamedTaha98/ccdf734f13299efb73ff0b12f7ce429f to your computer and use it in GitHub Desktop.
Save MohamedTaha98/ccdf734f13299efb73ff0b12f7ce429f to your computer and use it in GitHub Desktop.
// Djb2 hash function
unsigned long hash(char *str) {
unsigned long hash = 5381;
int c;
while ((c = *str++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash % NUM_BUCKETS;
}
@PeterTreichel
Copy link

Thanks for the code! helped me build a hash table for CS50 course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment