summaryrefslogtreecommitdiff
path: root/src/libstddjb/cdb_hash.c
blob: 85a11c1993fede1a966b07debcfd9ff3cc5200ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* ISC license. */

#include <stdint.h>
#include <skalibs/cdb.h>

uint32_t cdb_hashadd (uint32_t h, unsigned char c)
{
  h += (h << 5) ;
  return h ^ c ;
}

uint32_t cdb_hash (char const *buf, unsigned int len)
{
  uint32_t h = CDB_HASHSTART ;
  while (len--) h = cdb_hashadd(h, *buf++) ;
  return h ;
}