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 #include "string-view.h"
10
11 72922 static inline size_t fnv_1a_init(void)
12 {
13 72922 return (BITSIZE(size_t) >= 64) ? 14695981039346656037ULL : 2166136261U;
14 }
15
16 72922 static inline size_t fnv_1a_prime(void)
17 {
18 72922 return (BITSIZE(size_t) >= 64) ? 1099511628211ULL : 16777619U;
19 }
20
21 // https://datatracker.ietf.org/doc/html/draft-eastlake-fnv-31#name-fnv-basics
22 70130 static inline size_t fnv_1a_hash(StringView sv)
23 {
24 70130 const size_t prime = fnv_1a_prime();
25 70130 size_t hash = fnv_1a_init();
26
27
2/2
✓ Branch 4 → 3 taken 459322 times.
✓ Branch 4 → 5 taken 70130 times.
529452 while (sv.length--) {
28 459322 hash ^= (unsigned char)*sv.data++;
29 459322 hash *= prime;
30 }
31
32 70130 return hash;
33 }
34
35 2792 static inline size_t fnv_1a_hash_icase(StringView sv)
36 {
37 2792 const size_t prime = fnv_1a_prime();
38 2792 size_t hash = fnv_1a_init();
39
40
2/2
✓ Branch 4 → 3 taken 27256 times.
✓ Branch 4 → 5 taken 2792 times.
30048 while (sv.length--) {
41 27256 hash ^= ascii_tolower(*sv.data++);
42 27256 hash *= prime;
43 }
44
45 2792 return hash;
46 }
47
48 #endif
49