source src/oidmap.c
Line | Flow | Count | Block(s) | Source |
---|---|---|---|---|
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 | 630238 | 2 | GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid) | |
20 | - | { | ||
21 | - | khint_t h; | ||
22 | 630238 | 2 | memcpy(&h, oid, sizeof(khint_t)); | |
23 | 630238 | 2 | return h; | |
24 | - | } | ||
25 | - | |||
26 | 490700 | 2,2,2,2,2,2,2 | __KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal) | |
27 | - | |||
28 | 9383 | 2 | int git_oidmap_new(git_oidmap **out) | |
29 | - | { | ||
30 | 9383 | 2 | *out = kh_init(oid); | |
31 | 9383 | 3,4 | GIT_ERROR_CHECK_ALLOC(*out); | |
32 | - | |||
33 | 9383 | 5 | return 0; | |
34 | - | } | ||
35 | - | |||
36 | 9382 | 2 | void git_oidmap_free(git_oidmap *map) | |
37 | - | { | ||
38 | 9382 | 2 | kh_destroy(oid, map); | |
39 | 9381 | 3 | } | |
40 | - | |||
41 | 2108 | 2 | void git_oidmap_clear(git_oidmap *map) | |
42 | - | { | ||
43 | 2108 | 2 | kh_clear(oid, map); | |
44 | 2108 | 3 | } | |
45 | - | |||
46 | 16381 | 2 | size_t git_oidmap_size(git_oidmap *map) | |
47 | - | { | ||
48 | 16381 | 2 | return kh_size(map); | |
49 | - | } | ||
50 | - | |||
51 | - | 2 | suppressed: function cannot be solved git_oidmap_get (automatic due to inconsistent arc counts in .gcda files)void *git_oidmap_get(git_oidmap *map, const git_oid *key) | |
52 | - | { | ||
53 | - | 2 | suppressed: function cannot be solved git_oidmap_get (automatic due to inconsistent arc counts in .gcda files) size_t idx = kh_get(oid, map, key); | |
54 | - | 3,4 | suppressed: function cannot be solved git_oidmap_get (automatic due to inconsistent arc counts in .gcda files) if (idx == kh_end(map) || !kh_exist(map, idx)) | |
55 | - | 5 | suppressed: function cannot be solved git_oidmap_get (automatic due to inconsistent arc counts in .gcda files) return NULL; | |
56 | - | 6 | suppressed: function cannot be solved git_oidmap_get (automatic due to inconsistent arc counts in .gcda files) return kh_val(map, idx); | |
57 | - | } | ||
58 | - | |||
59 | 94886 | 2 | int git_oidmap_set(git_oidmap *map, const git_oid *key, void *value) | |
60 | - | { | ||
61 | - | size_t idx; | ||
62 | - | int rval; | ||
63 | - | |||
64 | 94886 | 2 | idx = kh_put(oid, map, key, &rval); | |
65 | 94886 | 3 | if (rval < 0) | |
66 | ##### | 4 | return -1; | |
67 | - | |||
68 | 94886 | 5 | if (rval == 0) | |
69 | 30338 | 6 | kh_key(map, idx) = key; | |
70 | - | |||
71 | 94886 | 7 | kh_val(map, idx) = value; | |
72 | - | |||
73 | 94886 | 7 | return 0; | |
74 | - | } | ||
75 | - | |||
76 | 16153 | 2 | int git_oidmap_delete(git_oidmap *map, const git_oid *key) | |
77 | - | { | ||
78 | 16153 | 2 | khiter_t idx = kh_get(oid, map, key); | |
79 | 16153 | 3 | if (idx == kh_end(map)) | |
80 | ##### | 4 | return GIT_ENOTFOUND; | |
81 | 16153 | 5 | kh_del(oid, map, idx); | |
82 | 16153 | 6 | return 0; | |
83 | - | } | ||
84 | - | |||
85 | 25647 | 2 | int git_oidmap_exists(git_oidmap *map, const git_oid *key) | |
86 | - | { | ||
87 | 25647 | 2 | return kh_get(oid, map, key) != kh_end(map); | |
88 | - | } | ||
89 | - | |||
90 | 48900 | 2 | int git_oidmap_iterate(void **value, git_oidmap *map, size_t *iter, const git_oid **key) | |
91 | - | { | ||
92 | 48900 | 2 | size_t i = *iter; | |
93 | - | |||
94 | 6362911 | 2,4,5 | while (i < map->n_buckets && !kh_exist(map, i)) | |
95 | 6314011 | 3 | i++; | |
96 | - | |||
97 | 48900 | 6 | if (i >= map->n_buckets) | |
98 | 3574 | 7 | return GIT_ITEROVER; | |
99 | - | |||
100 | 45326 | 8 | if (key) | |
101 | 16153 | 9 | *key = kh_key(map, i); | |
102 | 45326 | 10 | if (value) | |
103 | 45326 | 11 | *value = kh_value(map, i); | |
104 | 45326 | 12 | *iter = ++i; | |
105 | - | |||
106 | 45326 | 12 | return 0; | |
107 | - | } |