O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
hashes.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
12/* ************************************************************************** */
13
14#include "o2s/private_prepro.h" // FNV1A_*
15#include "o2s/string.h"
16
18uint32_t cstring_fnv1a_32(const char* cstring, size_t length)
19{
20 uint32_t c;
21 uint32_t hash;
22
23 hash = FNV1A_0();
24 while (length --> 0)
25 {
26 c = (unsigned char)*cstring++;
27 hash ^= c;
28 hash *= FNV1A_F;
29 }
30 return hash;
31}
32
34uint32_t string_fnv1a_32(const string_t* self)
35{
36 return cstring_fnv1a_32(string_get(self, 0), string_length(self));
37}
uint32_t string_fnv1a_32(const string_t *self)
Fowler–Noll–Vo hash function, on 32 bits.
Definition hashes.c:34
uint32_t cstring_fnv1a_32(const char *cstring, size_t length)
Fowler–Noll–Vo hash function, on 32 bits.
Definition hashes.c:18
Dynamic string implementation.
array_t string_t
A string is an array of char.
Definition string.h:30