27 lines
452 B
C
Raw Normal View History

2015-06-04 21:20:25 +02:00
/* public domain */
/* gcc -O3 -o djb2 djb2.c */
#include <stdio.h>
#include <stdint.h>
2015-06-04 21:26:40 +02:00
static uint32_t djb2(const char* str)
2015-06-04 21:20:25 +02:00
{
2015-06-04 21:26:40 +02:00
const unsigned char* aux = (const unsigned char*)str;
uint32_t hash = 5381;
2015-06-04 21:20:25 +02:00
2015-06-04 21:26:40 +02:00
while (*aux)
hash = (hash << 5) + hash + *aux++;
2015-06-04 21:20:25 +02:00
2015-06-04 21:26:40 +02:00
return hash;
2015-06-04 21:20:25 +02:00
}
2015-06-04 21:26:40 +02:00
int main(int argc, const char* argv[])
2015-06-04 21:20:25 +02:00
{
2015-06-04 21:26:40 +02:00
int i;
2015-06-04 21:20:25 +02:00
2015-06-04 21:26:40 +02:00
for (i = 1; i < argc; i++)
printf( "0x%08xU: %s\n", djb2( argv[ i ] ), argv[ i ] );
return 0;
2015-06-04 21:20:25 +02:00
}