mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
util: add a sdbm hash implementation
This commit is contained in:
parent
663c43c139
commit
34b814349b
1 changed files with 14 additions and 0 deletions
14
util.h
14
util.h
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <threads.h>
|
||||
|
||||
#define ALEN(v) (sizeof(v) / sizeof((v)[0]))
|
||||
|
|
@ -21,3 +22,16 @@ thrd_err_as_string(int thrd_err)
|
|||
|
||||
return "unknown error";
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
sdbm_hash(const char *s)
|
||||
{
|
||||
uint64_t hash = 0;
|
||||
|
||||
for (; *s != '\0'; s++) {
|
||||
int c = *s;
|
||||
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue