deps/libgit2/src/util/strmap.c

filter: Statementstmt 92.4% 49 / 53 Branchbran 72.6% 77 / 106 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 79.2% 126 / 159 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« deps/libgit2/src/libgit2/index.h ↑ Summary deps/libgit2/src/util/allocators/stdalloc.c »
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7  
8 #include "strmap.h"
9  
10 #define kmalloc git__malloc
11 #define kcalloc git__calloc
12 #define krealloc git__realloc
13 #define kreallocarray git__reallocarray
14 #define kfree git__free
15 #include "khash.h"
16  
17 __KHASH_TYPE(str, const char *, void *)
18  
19 99228 ▶__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
Branch: 42 branches
BranchTrueFalseTotal
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 6 0 6
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 6 0 6
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 5453 11659 17112
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 5453 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 0 0
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 5453 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 13187 3925 17112
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 1 4383 4384
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 4384 4384
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 4384 3925 8309
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 1 4383 4384
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 4383 0 4383
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 3925 0 3925
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 3925 0 3925
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 1 3924 3925
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 17111 1 17112
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 1 0 1
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 2490 2963 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 5453 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 1774 3679 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 5453 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 1774 3679 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 5453 0 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 5453 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 5453 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 5453 0 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 18594 6202 24796
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 872 18596 19468
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 11409 7187 18596
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 2 11407 11409
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 24796 5453 30249
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 5453 5453
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 27668 2712 30380
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 10371 10371
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 19157 18882 38039
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 3 19154 19157
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 10368 8786 19154
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 18882 8786 27668
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 508 0 508
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 95 413 508
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 0 95 95
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) 2624 0 2624
20  
21 2720 int git_strmap_new(git_strmap **out)
22 {
23 2720 *out = kh_init(str);
24 2720 ▶ GIT_ERROR_CHECK_ALLOC(*out);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(*out); 0 2720 2720
25  
26 2720 return 0;
27 }
28  
29 2624 void git_strmap_free(git_strmap *map)
30 {
31 2624 kh_destroy(str, map);
32 2624 }
33  
34 508 void git_strmap_clear(git_strmap *map)
35 {
36 508 kh_clear(str, map);
37 508 }
38  
39 101 size_t git_strmap_size(git_strmap *map)
40 {
41 101 return kh_size(map);
42 }
43  
44 30371 void *git_strmap_get(git_strmap *map, const char *key)
45 {
46 30371 size_t idx = kh_get(str, map, key);
47 30371 ▶ if (idx == kh_end(map) || !kh_exist(map, idx))
Branch: 2 branches
BranchTrueFalseTotal
if (idx == kh_end(map) || !kh_exist(map, idx)) 8777 21594 30371
if (idx == kh_end(map) || !kh_exist(map, idx)) 0 8777 8777
48 21594 return NULL;
49 8777 return kh_val(map, idx);
50 }
51  
52 17112 int git_strmap_set(git_strmap *map, const char *key, void *value)
53 {
54 size_t idx;
55 int rval;
56  
57 17112 idx = kh_put(str, map, key, &rval);
58 17112 ▶ if (rval < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rval < 0) 0 17112 17112
59 0 return -1;
60  
61 17112 ▶ if (rval == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rval == 0) 0 17112 17112
62 0 kh_key(map, idx) = key;
63  
64 17112 kh_val(map, idx) = value;
65  
66 17112 return 0;
67 }
68  
69 6 int git_strmap_delete(git_strmap *map, const char *key)
70 {
71 6 khiter_t idx = kh_get(str, map, key);
72 6 ▶ if (idx == kh_end(map))
Branch: 1 branch
BranchTrueFalseTotal
if (idx == kh_end(map)) 0 6 6
73 0 return GIT_ENOTFOUND;
74 6 kh_del(str, map, idx);
75 6 return 0;
76 }
77  
78 3 int git_strmap_exists(git_strmap *map, const char *key)
79 {
80 3 return kh_get(str, map, key) != kh_end(map);
81 }
82  
83 19890 int git_strmap_iterate(void **value, git_strmap *map, size_t *iter, const char **key)
84 {
85 19890 size_t i = *iter;
86  
87 37762 ▶ while (i < map->n_buckets && !kh_exist(map, i))
Branch: 2 branches
BranchTrueFalseTotal
while (i < map->n_buckets && !kh_exist(map, i)) 35172 2590 37762
while (i < map->n_buckets && !kh_exist(map, i)) 17872 17300 35172
88 17872 i++;
89  
90 19890 ▶ if (i >= map->n_buckets)
Branch: 1 branch
BranchTrueFalseTotal
if (i >= map->n_buckets) 2590 17300 19890
91 2590 return GIT_ITEROVER;
92  
93 17300 ▶ if (key)
Branch: 1 branch
BranchTrueFalseTotal
if (key) 0 17300 17300
94 0 *key = kh_key(map, i);
95 17300 ▶ if (value)
Branch: 1 branch
BranchTrueFalseTotal
if (value) 17300 0 17300
96 17300 *value = kh_val(map, i);
97 17300 *iter = ++i;
98  
99 17300 return 0;
100 }
« deps/libgit2/src/libgit2/index.h ↑ Summary deps/libgit2/src/util/allocators/stdalloc.c »