all repos — xrxs @ 6ea6f9be6bfe521b32bcd0c320f105c105d19c0c

experimental networked application/game server with 9p

hash.c (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>

unsigned long long hash(char* str) {
  unsigned long long h;
  unsigned char* p;

  h = 0;
  for (p = (unsigned char*)str; *p != '\0'; p++)
    h = 37 * h + *p;
  return h; // or, h % ARRAY_SIZE;
}

int main(int argc, char** argv) {
  printf("%llu\n", hash(argv[1]));
  return 0;
}