This commit is contained in:
Imbus 2025-06-25 08:41:33 +02:00
parent 355f96d5e7
commit f34dfcdccd

11
djb2.c
View file

@ -1,15 +1,14 @@
#include <stdio.h>
/*
* Simple hash function djb2, as in Daniel J. Berenstein.
*/
unsigned long djb2(const char *str) {
unsigned long h = 5381;
int c;
while ((c = *str++)) {
h = ((h << 5) + h) + c;
// Essentially equal to:
// h = h * 33 + c;
}
while ((c = *str++)) h = ((h << 5) + h) + c; // h = h * 33 + c;
return h;
}