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 "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 1233779 2,2,2,2,2,2,2 __KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
20 -
21 130492 2 int git_strmap_new(git_strmap **out)
22 - {
23 130492 2 *out = kh_init(str);
24 130486 3,4 GIT_ERROR_CHECK_ALLOC(*out);
25 -
26 130486 5 return 0;
27 - }
28 -
29 130521 2 void git_strmap_free(git_strmap *map)
30 - {
31 130521 2 kh_destroy(str, map);
32 130527 3 }
33 -
34 17227 2 void git_strmap_clear(git_strmap *map)
35 - {
36 17227 2 kh_clear(str, map);
37 17227 3 }
38 -
39 1121 2 size_t git_strmap_size(git_strmap *map)
40 - {
41 1121 2 return kh_size(map);
42 - }
43 -
44 - 2 suppressed: function cannot be solved git_strmap_get (automatic due to inconsistent arc counts in .gcda files)void *git_strmap_get(git_strmap *map, const char *key)
45 - {
46 - 2 suppressed: function cannot be solved git_strmap_get (automatic due to inconsistent arc counts in .gcda files) size_t idx = kh_get(str, map, key);
47 - 3,4 suppressed: function cannot be solved git_strmap_get (automatic due to inconsistent arc counts in .gcda files) if (idx == kh_end(map) || !kh_exist(map, idx))
48 - 5 suppressed: function cannot be solved git_strmap_get (automatic due to inconsistent arc counts in .gcda files) return NULL;
49 - 6 suppressed: function cannot be solved git_strmap_get (automatic due to inconsistent arc counts in .gcda files) return kh_val(map, idx);
50 - }
51 -
52 453032 2 int git_strmap_set(git_strmap *map, const char *key, void *value)
53 - {
54 - size_t idx;
55 - int rval;
56 -
57 453032 2 idx = kh_put(str, map, key, &rval);
58 453325 3 if (rval < 0)
59 32 4 return -1;
60 -
61 453293 5 if (rval == 0)
62 488 6 kh_key(map, idx) = key;
63 -
64 453293 7 kh_val(map, idx) = value;
65 -
66 453293 7 return 0;
67 - }
68 -
69 2565 2 int git_strmap_delete(git_strmap *map, const char *key)
70 - {
71 2565 2 khiter_t idx = kh_get(str, map, key);
72 2565 3 if (idx == kh_end(map))
73 18 4 return GIT_ENOTFOUND;
74 2547 5 kh_del(str, map, idx);
75 2547 6 return 0;
76 - }
77 -
78 9289 2 int git_strmap_exists(git_strmap *map, const char *key)
79 - {
80 9289 2 return kh_get(str, map, key) != kh_end(map);
81 - }
82 -
83 33855 2 int git_strmap_iterate(void **value, git_strmap *map, size_t *iter, const char **key)
84 - {
85 33855 2 size_t i = *iter;
86 -
87 59543 2,4,5 while (i < map->n_buckets && !kh_exist(map, i))
88 25688 3 i++;
89 -
90 33855 6 if (i >= map->n_buckets)
91 6295 7 return GIT_ITEROVER;
92 -
93 27560 8 if (key)
94 1085 9 *key = kh_key(map, i);
95 27560 10 if (value)
96 27560 11 *value = kh_val(map, i);
97 27560 12 *iter = ++i;
98 -
99 27560 12 return 0;
100 - }