deps/libgit2/src/libgit2/offmap.c

filter: Statementstmt 67.9% 36 / 53 Branchbran 28.3% 30 / 106 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 41.5% 66 / 159 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« deps/libgit2/src/libgit2/proxy.c ↑ Summary deps/libgit2/src/libgit2/oid.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 "offmap.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(off, off64_t, void *)
18  
19 0 ▶__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
Branch: 42 branches
BranchTrueFalseTotal
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 2 0 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 2 0 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 2 0 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 2 0 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 2 0 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 2 0 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 2 2
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 7 7
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 0 0 0
__KHASH_IMPL(off, static kh_inline, off64_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) 8 0 8
20  
21  
22 9 int git_offmap_new(git_offmap **out)
23 {
24 9 *out = kh_init(off);
25 9 ▶ GIT_ERROR_CHECK_ALLOC(*out);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(*out); 0 9 9
26  
27 9 return 0;
28 }
29  
30 8 void git_offmap_free(git_offmap *map)
31 {
32 8 kh_destroy(off, map);
33 8 }
34  
35 0 void git_offmap_clear(git_offmap *map)
36 {
37 0 kh_clear(off, map);
38 0 }
39  
40 0 size_t git_offmap_size(git_offmap *map)
41 {
42 0 return kh_size(map);
43 }
44  
45 5 void *git_offmap_get(git_offmap *map, const off64_t key)
46 {
47 5 size_t idx = kh_get(off, map, key);
48 5 ▶ if (idx == kh_end(map) || !kh_exist(map, idx))
Branch: 2 branches
BranchTrueFalseTotal
if (idx == kh_end(map) || !kh_exist(map, idx)) 0 5 5
if (idx == kh_end(map) || !kh_exist(map, idx)) 0 0 0
49 5 return NULL;
50 0 return kh_val(map, idx);
51 }
52  
53 2 int git_offmap_set(git_offmap *map, const off64_t key, void *value)
54 {
55 size_t idx;
56 int rval;
57  
58 2 idx = kh_put(off, map, key, &rval);
59 2 ▶ if (rval < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rval < 0) 0 2 2
60 0 return -1;
61  
62 2 ▶ if (rval == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rval == 0) 0 2 2
63 0 kh_key(map, idx) = key;
64  
65 2 kh_val(map, idx) = value;
66  
67 2 return 0;
68 }
69  
70 0 int git_offmap_delete(git_offmap *map, const off64_t key)
71 {
72 0 khiter_t idx = kh_get(off, map, key);
73 0 ▶ if (idx == kh_end(map))
Branch: 1 branch
BranchTrueFalseTotal
if (idx == kh_end(map)) 0 0 0
74 0 return GIT_ENOTFOUND;
75 0 kh_del(off, map, idx);
76 0 return 0;
77 }
78  
79 2 int git_offmap_exists(git_offmap *map, const off64_t key)
80 {
81 2 return kh_get(off, map, key) != kh_end(map);
82 }
83  
84 10 int git_offmap_iterate(void **value, git_offmap *map, size_t *iter, off64_t *key)
85 {
86 10 size_t i = *iter;
87  
88 16 ▶ while (i < map->n_buckets && !kh_exist(map, i))
Branch: 2 branches
BranchTrueFalseTotal
while (i < map->n_buckets && !kh_exist(map, i)) 8 8 16
while (i < map->n_buckets && !kh_exist(map, i)) 6 2 8
89 6 i++;
90  
91 10 ▶ if (i >= map->n_buckets)
Branch: 1 branch
BranchTrueFalseTotal
if (i >= map->n_buckets) 8 2 10
92 8 return GIT_ITEROVER;
93  
94 2 ▶ if (key)
Branch: 1 branch
BranchTrueFalseTotal
if (key) 0 2 2
95 0 *key = kh_key(map, i);
96 2 ▶ if (value)
Branch: 1 branch
BranchTrueFalseTotal
if (value) 2 0 2
97 2 *value = kh_value(map, i);
98 2 *iter = ++i;
99  
100 2 return 0;
101 }
« deps/libgit2/src/libgit2/proxy.c ↑ Summary deps/libgit2/src/libgit2/oid.c »