aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/u_hash.h
blob: 2b54ae6e6be49be1fc867f511fe2d3341ae3ca8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once

#include <stddef.h>

static inline size_t
hashs(size_t h, const char *s)
{
   while (*s) h = (unsigned char)*s++ + h*65599;
   return h;
}

static inline size_t
hashb(size_t h, const void *d, size_t n)
{
   const unsigned char *b = d;
   while (n--) h = *b++ + h*65599;
   return h;
}

static inline size_t
ptrhash(const void *p) {
   return (size_t)p * 2654435761u;
}