Commit df42f3689bb9345438fba18178f8e4fc61e631dd

Patrick Steinhardt 2018-12-01T10:54:57

idxmap: remove legacy low-level interface Remove the low-level interface that was exposing implementation details of `git_idxmap` 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.

diff --git a/src/idxmap.c b/src/idxmap.c
index d7aa4ea..e75887c 100644
--- a/src/idxmap.c
+++ b/src/idxmap.c
@@ -88,9 +88,8 @@ int git_idxmap_icase_resize(git_idxmap_icase *map, size_t size)
 
 void *git_idxmap_get(git_idxmap *map, const git_index_entry *key)
 {
-	size_t idx = git_idxmap_lookup_index(map, key);
-	if (!git_idxmap_valid_index(map, idx) ||
-	    !git_idxmap_has_data(map, idx))
+	size_t idx = kh_get(idx, map, key);
+	if (idx == kh_end(map) || !kh_exist(map, idx))
 		return NULL;
 	return kh_val(map, idx);
 }
@@ -131,9 +130,8 @@ int git_idxmap_icase_set(git_idxmap_icase *map, const git_index_entry *key, void
 
 void *git_idxmap_icase_get(git_idxmap_icase *map, const git_index_entry *key)
 {
-	size_t idx = git_idxmap_icase_lookup_index(map, key);
-	if (!git_idxmap_icase_valid_index(map, idx) ||
-	    !git_idxmap_icase_has_data(map, idx))
+	size_t idx = kh_get(idxicase, map, key);
+	if (idx == kh_end(map) || !kh_exist(map, idx))
 		return NULL;
 	return kh_val(map, idx);
 }
@@ -162,63 +160,18 @@ void git_idxmap_icase_insert(git_idxmap_icase *map, const git_index_entry *key, 
 
 int git_idxmap_delete(git_idxmap *map, const git_index_entry *key)
 {
-	khiter_t idx = git_idxmap_lookup_index(map, key);
-	if (!git_idxmap_valid_index(map, idx))
+	khiter_t idx = kh_get(idx, map, key);
+	if (idx == kh_end(map))
 		return GIT_ENOTFOUND;
-	git_idxmap_delete_at(map, idx);
+	kh_del(idx, map, idx);
 	return 0;
 }
 
 int git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key)
 {
-	khiter_t idx = git_idxmap_icase_lookup_index(map, key);
-	if (!git_idxmap_valid_index((git_idxmap *)map, idx))
+	khiter_t idx = kh_get(idxicase, map, key);
+	if (idx == kh_end(map))
 		return GIT_ENOTFOUND;
-	git_idxmap_icase_delete_at(map, idx);
-	return 0;
-}
-
-size_t git_idxmap_lookup_index(git_idxmap *map, const git_index_entry *key)
-{
-	return kh_get(idx, map, key);
-}
-
-size_t git_idxmap_icase_lookup_index(git_idxmap_icase *map, const git_index_entry *key)
-{
-	return kh_get(idxicase, map, key);
-}
-
-void *git_idxmap_value_at(git_idxmap *map, size_t idx)
-{
-	return kh_val(map, idx);
-}
-
-int git_idxmap_valid_index(git_idxmap *map, size_t idx)
-{
-	return idx != kh_end(map);
-}
-
-int git_idxmap_icase_valid_index(git_idxmap_icase *map, size_t idx)
-{
-	return idx != kh_end(map);
-}
-
-int git_idxmap_has_data(git_idxmap *map, size_t idx)
-{
-	return kh_exist(map, idx);
-}
-
-int git_idxmap_icase_has_data(git_idxmap_icase *map, size_t idx)
-{
-	return kh_exist(map, idx);
-}
-
-void git_idxmap_delete_at(git_idxmap *map, size_t idx)
-{
-	kh_del(idx, map, idx);
-}
-
-void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx)
-{
 	kh_del(idxicase, map, idx);
+	return 0;
 }
diff --git a/src/idxmap.h b/src/idxmap.h
index ce9f084..76170ef 100644
--- a/src/idxmap.h
+++ b/src/idxmap.h
@@ -174,18 +174,4 @@ int git_idxmap_delete(git_idxmap *map, const git_index_entry *key);
  */
 int git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key);
 
-void git_idxmap_insert(git_idxmap *map, const git_index_entry *key, void *value, int *rval);
-void git_idxmap_icase_insert(git_idxmap_icase *map, const git_index_entry *key, void *value, int *rval);
-
-size_t git_idxmap_lookup_index(git_idxmap *map, const git_index_entry *key);
-size_t git_idxmap_icase_lookup_index(git_idxmap_icase *map, const git_index_entry *key);
-void *git_idxmap_value_at(git_idxmap *map, size_t idx);
-int git_idxmap_valid_index(git_idxmap *map, size_t idx);
-int git_idxmap_icase_valid_index(git_idxmap_icase *map, size_t idx);
-int git_idxmap_has_data(git_idxmap *map, size_t idx);
-int git_idxmap_icase_has_data(git_idxmap_icase *map, size_t idx);
-
-void git_idxmap_delete_at(git_idxmap *map, size_t idx);
-void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);
-
 #endif