hash/sdbm.h

24 lines
451 B
C
Raw Permalink Normal View History

2024-08-16 19:08:58 +00:00
#ifndef SDBM_H
#define SDBM_H
2024-08-16 19:32:35 +00:00
2024-08-16 19:08:58 +00:00
#include <stdlib.h>
static unsigned long sdbm(char *str) {
unsigned long hash = 0;
for (int c = *str; c != 0; c = *str++)
hash = c + (hash << 6) + (hash << 16) - hash;
return hash;
}
static unsigned long sdbm_clean(char *str, size_t size) {
unsigned long hash = 0;
for (size_t i = 0; i < size + 1; i++)
hash = *str + (hash << 6) + (hash << 16) - hash;
return hash;
}
#endif