Tinyhash
This is a library containing multiple C implementations of hashmap.
Loading...
Searching...
No Matches
hash.c
Go to the documentation of this file.
1#include <stdint.h>
2#include <stdlib.h>
3
8#define TH_HASH_INITIAL_VALUE 2166136261u
9
14#define TH_HASH_MUL_VALUE 16777619
15
16uint32_t th_hash(uint8_t *bytes, size_t size) {
17 if (bytes == NULL) {
18 return 0;
19 }
20
21 uint32_t hash = TH_HASH_INITIAL_VALUE;
22
23 for (int i = 0; i < size; i++) {
24 hash ^= bytes[i];
25 hash *= TH_HASH_MUL_VALUE;
26 }
27
28 return hash;
29}
#define TH_HASH_MUL_VALUE
Multiplier for hash function.
Definition hash.c:14
uint32_t th_hash(uint8_t *bytes, size_t size)
Compute an unsigned int from bytes.
Definition hash.c:16
#define TH_HASH_INITIAL_VALUE
Initial value for hash function.
Definition hash.c:8