offmap: remove legacy low-level interface Remove the low-level interface that was exposing implementation details of `git_offmap` to callers. From now on, only the high-level functions shall be used to retrieve or modify values of a map. Adjust remaining existing callers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
diff --git a/src/offmap.c b/src/offmap.c
index 162501d..ba86bc0 100644
--- a/src/offmap.c
+++ b/src/offmap.c
@@ -44,9 +44,8 @@ size_t git_offmap_size(git_offmap *map)
void *git_offmap_get(git_offmap *map, const git_off_t key)
{
- size_t idx = git_offmap_lookup_index(map, key);
- if (!git_offmap_valid_index(map, idx) ||
- !git_offmap_has_data(map, idx))
+ size_t idx = kh_get(off, map, key);
+ if (idx == kh_end(map) || !kh_exist(map, idx))
return NULL;
return kh_val(map, idx);
}
@@ -70,10 +69,10 @@ int git_offmap_set(git_offmap *map, const git_off_t key, void *value)
int git_offmap_delete(git_offmap *map, const git_off_t key)
{
- khiter_t idx = git_offmap_lookup_index(map, key);
- if (!git_offmap_valid_index(map, idx))
+ khiter_t idx = kh_get(off, map, key);
+ if (idx == kh_end(map))
return GIT_ENOTFOUND;
- git_offmap_delete_at(map, idx);
+ kh_del(off, map, idx);
return 0;
}
@@ -86,79 +85,17 @@ int git_offmap_iterate(void **value, git_offmap *map, size_t *iter, git_off_t *k
{
size_t i = *iter;
- while (i < git_offmap_end(map) && !git_offmap_has_data(map, i))
+ while (i < map->n_buckets && !kh_exist(map, i))
i++;
- if (i >= git_offmap_end(map))
+ if (i >= map->n_buckets)
return GIT_ITEROVER;
if (key)
- *key = git_offmap_key_at(map, i);
+ *key = kh_key(map, i);
if (value)
- *value = git_offmap_value_at(map, i);
+ *value = kh_value(map, i);
*iter = ++i;
return 0;
}
-
-size_t git_offmap_lookup_index(git_offmap *map, const git_off_t key)
-{
- return kh_get(off, map, key);
-}
-
-int git_offmap_valid_index(git_offmap *map, size_t idx)
-{
- return idx != kh_end(map);
-}
-
-int git_offmap_has_data(git_offmap *map, size_t idx)
-{
- return kh_exist(map, idx);
-}
-
-git_off_t git_offmap_key_at(git_offmap *map, size_t idx)
-{
- return kh_key(map, idx);
-}
-
-void *git_offmap_value_at(git_offmap *map, size_t idx)
-{
- return kh_val(map, idx);
-}
-
-void git_offmap_set_value_at(git_offmap *map, size_t idx, void *value)
-{
- kh_val(map, idx) = value;
-}
-
-void git_offmap_delete_at(git_offmap *map, size_t idx)
-{
- kh_del(off, map, idx);
-}
-
-int git_offmap_put(git_offmap *map, const git_off_t key, int *err)
-{
- return kh_put(off, map, key, err);
-}
-
-void git_offmap_insert(git_offmap *map, const git_off_t key, void *value, int *rval)
-{
- khiter_t idx = kh_put(off, map, key, rval);
-
- if ((*rval) >= 0) {
- if ((*rval) == 0)
- kh_key(map, idx) = key;
- kh_val(map, idx) = value;
- }
-}
-
-size_t git_offmap_begin(git_offmap *map)
-{
- GIT_UNUSED(map);
- return 0;
-}
-
-size_t git_offmap_end(git_offmap *map)
-{
- return map->n_buckets;
-}
diff --git a/src/offmap.h b/src/offmap.h
index 456e2ae..6fa7d2f 100644
--- a/src/offmap.h
+++ b/src/offmap.h
@@ -120,22 +120,6 @@ int git_offmap_exists(git_offmap *map, const git_off_t key);
*/
int git_offmap_iterate(void **value, git_offmap *map, size_t *iter, git_off_t *key);
-size_t git_offmap_lookup_index(git_offmap *map, const git_off_t key);
-int git_offmap_valid_index(git_offmap *map, size_t idx);
-
-int git_offmap_has_data(git_offmap *map, size_t idx);
-
-git_off_t git_offmap_key_at(git_offmap *map, size_t idx);
-void *git_offmap_value_at(git_offmap *map, size_t idx);
-void git_offmap_set_value_at(git_offmap *map, size_t idx, void *value);
-void git_offmap_delete_at(git_offmap *map, size_t idx);
-
-int git_offmap_put(git_offmap *map, const git_off_t key, int *err);
-void git_offmap_insert(git_offmap *map, const git_off_t key, void *value, int *rval);
-
-size_t git_offmap_begin(git_offmap *map);
-size_t git_offmap_end(git_offmap *map);
-
#define git_offmap_foreach(h, kvar, vvar, code) { size_t __i = 0; \
while (git_offmap_iterate((void **) &(vvar), h, &__i, &(kvar)) == 0) { \
code; \