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

#include <stdint.h>

#include "cdb-internal.h"

#define CDB_HASHSTART 5381

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

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