sql-space-invaders/scripts/hash.c
Ari Archer 140f073d0a
Implement the C renderer.
Signed-off-by: Ari Archer <ari@ari.lt>
2025-02-04 00:10:56 +02:00

39 lines
713 B
C

#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
static uint64_t komihash(const char *key) {
uint64_t hash = 0;
while (*key) {
hash ^= (hash << 21);
hash ^= (hash >> 35);
hash ^= (hash << 4);
hash += (uint8_t)*key++;
}
return hash;
}
static void to_upper(char *str) {
while (*str) {
*str = toupper((unsigned char)*str);
++str;
}
}
int main(int argc, char *argv[]) {
if (argc < 2)
return 1;
const uint64_t hash = komihash(argv[1]);
char buf[1024] = {0};
strcpy(buf, argv[1]);
to_upper(buf);
printf("#define HASH_%s %juULL /* %s */\n", buf, hash, argv[1]);
return 0;
}