deps/libgit2/src/libgit2/oidmap.c

filter: Statementstmt 83.9% 47 / 56 Branchbran 69.8% 74 / 106 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.6% 121 / 162 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« deps/libgit2/src/libgit2/xdiff/xprepare.c ↑ Summary xs/Rebase/Operation.xs »
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 "oidmap.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(oid, const git_oid *, void *)
18  
19 5084 GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
20 {
21 khint_t h;
22 5084 memcpy(&h, oid->id, sizeof(khint_t));
23 5084 return h;
24 }
25  
26 0 ▶__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal)
Branch: 42 branches
BranchTrueFalseTotal
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 0 0
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 0 0
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 199 564 763
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 199 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 0 0
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 199 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 412 351 763
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 354 354
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 354 354
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 536 169 705
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 536 536
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 354 182 536
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 351 0 351
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 169 182 351
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 169 169
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 581 182 763
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 182 182
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 103 96 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 199 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 36 163 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 199 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 36 163 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 199 0 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 199 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 199 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 199 0 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 506 198 704
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 102 530 632
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 274 256 530
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 24 250 274
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 704 199 903
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 199 199
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 3791 215 4006
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 2045 2045
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 4279 1557 5836
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 0 4279 4279
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 2045 2234 4279
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 1557 2234 3791
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 38 0 38
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 32 6 38
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 15 17 32
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) 223 0 223
27  
28 225 int git_oidmap_new(git_oidmap **out)
29 {
30 225 *out = kh_init(oid);
31 225 ▶ GIT_ERROR_CHECK_ALLOC(*out);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(*out); 0 225 225
32  
33 225 return 0;
34 }
35  
36 223 void git_oidmap_free(git_oidmap *map)
37 {
38 223 kh_destroy(oid, map);
39 223 }
40  
41 38 void git_oidmap_clear(git_oidmap *map)
42 {
43 38 kh_clear(oid, map);
44 38 }
45  
46 163 size_t git_oidmap_size(git_oidmap *map)
47 {
48 163 return kh_size(map);
49 }
50  
51 3883 void *git_oidmap_get(git_oidmap *map, const git_oid *key)
52 {
53 3883 size_t idx = kh_get(oid, map, key);
54 3883 ▶ if (idx == kh_end(map) || !kh_exist(map, idx))
Branch: 2 branches
BranchTrueFalseTotal
if (idx == kh_end(map) || !kh_exist(map, idx)) 2221 1662 3883
if (idx == kh_end(map) || !kh_exist(map, idx)) 0 2221 2221
55 1662 return NULL;
56 2221 return kh_val(map, idx);
57 }
58  
59 763 int git_oidmap_set(git_oidmap *map, const git_oid *key, void *value)
60 {
61 size_t idx;
62 int rval;
63  
64 763 idx = kh_put(oid, map, key, &rval);
65 763 ▶ if (rval < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rval < 0) 0 763 763
66 0 return -1;
67  
68 763 ▶ if (rval == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (rval == 0) 182 581 763
69 182 kh_key(map, idx) = key;
70  
71 763 kh_val(map, idx) = value;
72  
73 763 return 0;
74 }
75  
76 0 int git_oidmap_delete(git_oidmap *map, const git_oid *key)
77 {
78 0 khiter_t idx = kh_get(oid, map, key);
79 0 ▶ if (idx == kh_end(map))
Branch: 1 branch
BranchTrueFalseTotal
if (idx == kh_end(map)) 0 0 0
80 0 return GIT_ENOTFOUND;
81 0 kh_del(oid, map, idx);
82 0 return 0;
83 }
84  
85 123 int git_oidmap_exists(git_oidmap *map, const git_oid *key)
86 {
87 123 return kh_get(oid, map, key) != kh_end(map);
88 }
89  
90 753 int git_oidmap_iterate(void **value, git_oidmap *map, size_t *iter, const git_oid **key)
91 {
92 753 size_t i = *iter;
93  
94 1254 ▶ while (i < map->n_buckets && !kh_exist(map, i))
Branch: 2 branches
BranchTrueFalseTotal
while (i < map->n_buckets && !kh_exist(map, i)) 1080 174 1254
while (i < map->n_buckets && !kh_exist(map, i)) 501 579 1080
95 501 i++;
96  
97 753 ▶ if (i >= map->n_buckets)
Branch: 1 branch
BranchTrueFalseTotal
if (i >= map->n_buckets) 174 579 753
98 174 return GIT_ITEROVER;
99  
100 579 ▶ if (key)
Branch: 1 branch
BranchTrueFalseTotal
if (key) 0 579 579
101 0 *key = kh_key(map, i);
102 579 ▶ if (value)
Branch: 1 branch
BranchTrueFalseTotal
if (value) 579 0 579
103 579 *value = kh_value(map, i);
104 579 *iter = ++i;
105  
106 579 return 0;
107 }
« deps/libgit2/src/libgit2/xdiff/xprepare.c ↑ Summary xs/Rebase/Operation.xs »