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

#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 ;
}