summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-12-01 09:49:10 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 13:16:49 +0100
commitfdfabdc4e26b42848b07e0e8e70fc51faceab976 (patch)
tree4e75f98ad0196facd509881936219dc525c24253 /src
parent6a9117f557fed0afe4007c5de5158e0ebd3a187f (diff)
downloadlibgit2-fdfabdc4e26b42848b07e0e8e70fc51faceab976.tar.gz
strmap: remove legacy low-level interface
Remove the low-level interface that was exposing implementation details of `git_strmap` 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.
Diffstat (limited to 'src')
-rw-r--r--src/strmap.c110
-rw-r--r--src/strmap.h22
2 files changed, 9 insertions, 123 deletions
diff --git a/src/strmap.c b/src/strmap.c
index 1c7d5ef57..c6e5b6dc7 100644
--- a/src/strmap.c
+++ b/src/strmap.c
@@ -43,9 +43,8 @@ size_t git_strmap_size(git_strmap *map)
void *git_strmap_get(git_strmap *map, const char *key)
{
- size_t idx = git_strmap_lookup_index(map, key);
- if (!git_strmap_valid_index(map, idx) ||
- !git_strmap_has_data(map, idx))
+ size_t idx = kh_get(str, map, key);
+ if (idx == kh_end(map) || !kh_exist(map, idx))
return NULL;
return kh_val(map, idx);
}
@@ -69,10 +68,10 @@ int git_strmap_set(git_strmap *map, const char *key, void *value)
int git_strmap_delete(git_strmap *map, const char *key)
{
- khiter_t idx = git_strmap_lookup_index(map, key);
- if (!git_strmap_valid_index(map, idx))
+ khiter_t idx = kh_get(str, map, key);
+ if (idx == kh_end(map))
return GIT_ENOTFOUND;
- git_strmap_delete_at(map, idx);
+ kh_del(str, map, idx);
return 0;
}
@@ -85,108 +84,17 @@ int git_strmap_iterate(void **value, git_strmap *map, size_t *iter, const char *
{
size_t i = *iter;
- while (i < git_strmap_end(map) && !git_strmap_has_data(map, i))
+ while (i < map->n_buckets && !kh_exist(map, i))
i++;
- if (i >= git_strmap_end(map))
+ if (i >= map->n_buckets)
return GIT_ITEROVER;
if (key)
- *key = git_strmap_key(map, i);
+ *key = kh_key(map, i);
if (value)
- *value = git_strmap_value_at(map, i);
+ *value = kh_val(map, i);
*iter = ++i;
return 0;
}
-
-size_t git_strmap_lookup_index(git_strmap *map, const char *key)
-{
- return kh_get(str, map, key);
-}
-
-int git_strmap_valid_index(git_strmap *map, size_t idx)
-{
- return idx != kh_end(map);
-}
-
-int git_strmap_has_data(git_strmap *map, size_t idx)
-{
- return kh_exist(map, idx);
-}
-
-const char *git_strmap_key(git_strmap *map, size_t idx)
-{
- return kh_key(map, idx);
-}
-
-void git_strmap_set_key_at(git_strmap *map, size_t idx, char *key)
-{
- kh_val(map, idx) = key;
-}
-
-void *git_strmap_value_at(git_strmap *map, size_t idx)
-{
- return kh_val(map, idx);
-}
-
-void git_strmap_set_value_at(git_strmap *map, size_t idx, void *value)
-{
- kh_val(map, idx) = value;
-}
-
-void git_strmap_delete_at(git_strmap *map, size_t idx)
-{
- kh_del(str, map, idx);
-}
-
-int git_strmap_put(git_strmap *map, const char *key, int *err)
-{
- return kh_put(str, map, key, err);
-}
-
-void git_strmap_insert(git_strmap *map, const char *key, void *value, int *rval)
-{
- khiter_t idx = kh_put(str, map, key, rval);
-
- if ((*rval) >= 0) {
- if ((*rval) == 0)
- kh_key(map, idx) = key;
- kh_val(map, idx) = value;
- }
-}
-
-size_t git_strmap_begin(git_strmap *map)
-{
- GIT_UNUSED(map);
- return 0;
-}
-
-size_t git_strmap_end(git_strmap *map)
-{
- return map->n_buckets;
-}
-
-int git_strmap_next(
- void **data,
- size_t* iter,
- git_strmap *map)
-{
- if (!map)
- return GIT_ERROR;
-
- while (*iter != git_strmap_end(map)) {
- if (!(git_strmap_has_data(map, *iter))) {
- ++(*iter);
- continue;
- }
-
- *data = git_strmap_value_at(map, *iter);
-
- ++(*iter);
-
- return GIT_OK;
- }
-
- return GIT_ITEROVER;
-}
diff --git a/src/strmap.h b/src/strmap.h
index ce547ac3a..9f5e4cc8b 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -118,20 +118,6 @@ int git_strmap_exists(git_strmap *map, const char *key);
*/
int git_strmap_iterate(void **value, git_strmap *map, size_t *iter, const char **key);
-size_t git_strmap_lookup_index(git_strmap *map, const char *key);
-int git_strmap_valid_index(git_strmap *map, size_t idx);
-
-int git_strmap_has_data(git_strmap *map, size_t idx);
-
-const char *git_strmap_key(git_strmap *map, size_t idx);
-void git_strmap_set_key_at(git_strmap *map, size_t idx, char *key);
-void *git_strmap_value_at(git_strmap *map, size_t idx);
-void git_strmap_set_value_at(git_strmap *map, size_t idx, void *value);
-void git_strmap_delete_at(git_strmap *map, size_t idx);
-
-int git_strmap_put(git_strmap *map, const char *key, int *err);
-void git_strmap_insert(git_strmap *map, const char *key, void *value, int *rval);
-
#define git_strmap_foreach(h, kvar, vvar, code) { size_t __i = 0; \
while (git_strmap_iterate((void **) &(vvar), h, &__i, &(kvar)) == 0) { \
code; \
@@ -142,12 +128,4 @@ void git_strmap_insert(git_strmap *map, const char *key, void *value, int *rval)
code; \
} }
-size_t git_strmap_begin(git_strmap *map);
-size_t git_strmap_end(git_strmap *map);
-
-int git_strmap_next(
- void **data,
- size_t *iter,
- git_strmap *map);
-
#endif