summaryrefslogtreecommitdiff
path: root/fnv.c
blob: af6532ceffed277cb0ce2d5487d537314b5d5db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdlib.h>
#include <stdint.h>

uint64_t fnv1_64(const void *src, size_t len)
{
	const unsigned char *d = (const unsigned char *)src;
	uint64_t h = 0xcbf29ce484222325;
	size_t i;
	for (i = 0; i < len; i++) {
		h *= 0x100000001b3;
		h ^= d[i];
	}
	return h;
}

uint64_t fnv1a_64(const void *src, size_t len)
{
	const unsigned char *d = (const unsigned char *)src;
	uint64_t h = 0xcbf29ce484222325;
	size_t i;
	for (i = 0; i < len; i++) {
		h ^= d[i];
		h *= 0x100000001b3;
	}
	return h;
}