summaryrefslogtreecommitdiff
path: root/src/dged/hash.c
blob: fce61afa6bf5d4fdb1f0e5dd6c0e4b862fac124c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "hash.h"

uint32_t hash_name(const char *s) {
  unsigned long hash = 5381;
  int c;

  while ((c = *s++))
    hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

  return hash;
}

uint32_t hash_name_s8(struct s8 s) {
  unsigned long hash = 5381;

  for (uint64_t i = 0; i < s.l; ++i)
    hash = ((hash << 5) + hash) + s.s[i]; /* hash * 33 + c */

  return hash;
}