-
-
Save yorickdewid/dc600cb52a4ab90747d2 to your computer and use it in GitHub Desktop.
djb2a hash algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
unsigned long hash(unsigned char *str) { | |
unsigned long hash = 5381; | |
int c; | |
while ((c = *str++)) | |
hash = hash * 33 ^ c; | |
return hash; | |
} | |
int main(int argc, char *argv[]) { | |
if (argc < 2) | |
return 1; | |
printf("hash %ld\n", hash(argv[1])); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment