dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 18 / 0 / 18
Functions: 100.0% 4 / 0 / 4
Branches: 100.0% 4 / 0 / 4

src/util/hash.h
Line Branch Exec Source
1 #ifndef UTIL_HASH_H
2 #define UTIL_HASH_H
3
4 #include <limits.h>
5 #include <stddef.h>
6 #include <stdint.h>
7 #include "ascii.h"
8 #include "macros.h"
9
10 72895 static inline size_t fnv_1a_init(void)
11 {
12 72895 return (BITSIZE(size_t) >= 64) ? 14695981039346656037ULL : 2166136261U;
13 }
14
15 72895 static inline size_t fnv_1a_prime(void)
16 {
17 72895 return (BITSIZE(size_t) >= 64) ? 1099511628211ULL : 16777619U;
18 }
19
20 // https://datatracker.ietf.org/doc/html/draft-eastlake-fnv-31#name-fnv-basics
21 70089 static inline size_t fnv_1a_hash(const char *str, size_t n)
22 {
23 70089 const size_t prime = fnv_1a_prime();
24 70089 size_t hash = fnv_1a_init();
25
2/2
✓ Branch 4 → 3 taken 459232 times.
✓ Branch 4 → 5 taken 70089 times.
529321 while (n--) {
26 459232 hash ^= (unsigned char)*str++;
27 459232 hash *= prime;
28 }
29 70089 return hash;
30 }
31
32 2806 static inline size_t fnv_1a_hash_icase(const char *str, size_t n)
33 {
34 2806 const size_t prime = fnv_1a_prime();
35 2806 size_t hash = fnv_1a_init();
36
2/2
✓ Branch 4 → 3 taken 27284 times.
✓ Branch 4 → 5 taken 2806 times.
30090 while (n--) {
37 27284 hash ^= ascii_tolower(*str++);
38 27284 hash *= prime;
39 }
40 2806 return hash;
41 }
42
43 #endif
44