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

uint64_t fnv1a64(uint8_t* buf, size_t size) {
	size_t i;
	uint64_t hash = 0xcbf29ce484222325;
	for (i = 0; i < size; i++, buf++) {
		hash ^= *buf;
		hash *= 0x100000001b3;
	}
	return hash;
}

uint32_t hash_string(const char* s) {
	uint32_t h = 2166136261u;
	for (; *s; s++) {
		h ^= *(uint8_t*)s;
		h *= 16777619;
	}
	return h;
}