File: djb2.c

package info (click to toggle)
retroarch 1.3.6%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 26,496 kB
  • ctags: 41,865
  • sloc: ansic: 250,395; cpp: 12,996; makefile: 3,500; objc: 3,266; xml: 2,141; python: 1,670; sh: 1,522; java: 798; asm: 542; perl: 393
file content (26 lines) | stat: -rw-r--r-- 452 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* public domain */
/* gcc -O3 -o djb2 djb2.c */

#include <stdio.h>
#include <stdint.h>

static uint32_t djb2(const char* str)
{
   const unsigned char* aux = (const unsigned char*)str;
   uint32_t hash = 5381;

   while (*aux)
      hash = (hash << 5) + hash + *aux++;

   return hash;
}

int main(int argc, const char* argv[])
{
   int i;

   for (i = 1; i < argc; i++)
      printf( "0x%08xU: %s\n", djb2( argv[ i ] ), argv[ i ] );

   return 0;
}