summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-11-30 12:14:43 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-15 13:16:48 +0100
commit7e926ef306166993131628b41a13f2b26aaf43de (patch)
tree30f8c5930e015536087077fd60aa0f75d0e9f6f9
parent351eeff3b2a666b8ead5302c1130629597438df6 (diff)
downloadlibgit2-7e926ef306166993131628b41a13f2b26aaf43de.tar.gz
maps: provide a uniform entry count interface
There currently exist two different function names for getting the entry count of maps, where offmaps offset and string maps use `num_entries` and OID maps use `size`. In most programming languages with built-in map types, this is simply called `size`, which is also shorter to type. Thus, this commit renames the other two functions `num_entries` to match the common way and adjusts all callers.
-rw-r--r--src/offmap.c2
-rw-r--r--src/offmap.h8
-rw-r--r--src/oidmap.h6
-rw-r--r--src/strmap.c2
-rw-r--r--src/strmap.h8
-rw-r--r--src/submodule.c2
-rw-r--r--src/tree.c4
-rw-r--r--tests/core/strmap.c9
-rw-r--r--tests/pack/sharing.c4
9 files changed, 32 insertions, 13 deletions
diff --git a/src/offmap.c b/src/offmap.c
index d4388cab6..2b447b392 100644
--- a/src/offmap.c
+++ b/src/offmap.c
@@ -37,7 +37,7 @@ void git_offmap_clear(git_offmap *map)
kh_clear(off, map);
}
-size_t git_offmap_num_entries(git_offmap *map)
+size_t git_offmap_size(git_offmap *map)
{
return kh_size(map);
}
diff --git a/src/offmap.h b/src/offmap.h
index 1280fd337..cde6c31c2 100644
--- a/src/offmap.h
+++ b/src/offmap.h
@@ -44,7 +44,13 @@ void git_offmap_free(git_offmap *map);
*/
void git_offmap_clear(git_offmap *map);
-size_t git_offmap_num_entries(git_offmap *map);
+/**
+ * Return the number of elements in the map.
+ *
+ * @parameter map map containing the elements
+ * @return number of elements in the map
+ */
+size_t git_offmap_size(git_offmap *map);
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);
diff --git a/src/oidmap.h b/src/oidmap.h
index 733357f61..c44f7228e 100644
--- a/src/oidmap.h
+++ b/src/oidmap.h
@@ -44,6 +44,12 @@ void git_oidmap_free(git_oidmap *map);
*/
void git_oidmap_clear(git_oidmap *map);
+/**
+ * Return the number of elements in the map.
+ *
+ * @parameter map map containing the elements
+ * @return number of elements in the map
+ */
size_t git_oidmap_size(git_oidmap *map);
size_t git_oidmap_lookup_index(git_oidmap *map, const git_oid *key);
diff --git a/src/strmap.c b/src/strmap.c
index 98b939fea..a2132285e 100644
--- a/src/strmap.c
+++ b/src/strmap.c
@@ -36,7 +36,7 @@ void git_strmap_clear(git_strmap *map)
kh_clear(str, map);
}
-size_t git_strmap_num_entries(git_strmap *map)
+size_t git_strmap_size(git_strmap *map)
{
return kh_size(map);
}
diff --git a/src/strmap.h b/src/strmap.h
index 5a43c6637..1b7f1a4b7 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -42,7 +42,13 @@ void git_strmap_free(git_strmap *map);
*/
void git_strmap_clear(git_strmap *map);
-size_t git_strmap_num_entries(git_strmap *map);
+/**
+ * Return the number of elements in the map.
+ *
+ * @parameter map map containing the elements
+ * @return number of elements in the map
+ */
+size_t git_strmap_size(git_strmap *map);
size_t git_strmap_lookup_index(git_strmap *map, const char *key);
int git_strmap_valid_index(git_strmap *map, size_t idx);
diff --git a/src/submodule.c b/src/submodule.c
index e11b544a2..72921fa3e 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -625,7 +625,7 @@ int git_submodule_foreach(
goto done;
if (!(error = git_vector_init(
- &snapshot, git_strmap_num_entries(submodules), submodule_cmp))) {
+ &snapshot, git_strmap_size(submodules), submodule_cmp))) {
git_strmap_foreach_value(submodules, sm, {
if ((error = git_vector_insert(&snapshot, sm)) < 0)
diff --git a/src/tree.c b/src/tree.c
index 9134451c6..cc6f93db5 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -344,7 +344,7 @@ unsigned int git_treebuilder_entrycount(git_treebuilder *bld)
{
assert(bld);
- return git_strmap_num_entries(bld->map);
+ return git_strmap_size(bld->map);
}
static int tree_error(const char *str, const char *path)
@@ -811,7 +811,7 @@ int git_treebuilder_write_with_buffer(git_oid *oid, git_treebuilder *bld, git_bu
git_buf_clear(tree);
- entrycount = git_strmap_num_entries(bld->map);
+ entrycount = git_strmap_size(bld->map);
if ((error = git_vector_init(&entries, entrycount, entry_sort_cmp)) < 0)
goto out;
diff --git a/tests/core/strmap.c b/tests/core/strmap.c
index e19ceaedf..d6af9773d 100644
--- a/tests/core/strmap.c
+++ b/tests/core/strmap.c
@@ -16,12 +16,13 @@ void test_core_strmap__cleanup(void)
void test_core_strmap__0(void)
{
- cl_assert(git_strmap_num_entries(g_table) == 0);
+ cl_assert(git_strmap_size(g_table) == 0);
}
-static void insert_strings(git_strmap *table, int count)
+static void insert_strings(git_strmap *table, size_t count)
{
- int i, j, over, err;
+ size_t i, j, over;
+ int err;
char *str;
for (i = 0; i < count; ++i) {
@@ -38,7 +39,7 @@ static void insert_strings(git_strmap *table, int count)
cl_assert(err >= 0);
}
- cl_assert((int)git_strmap_num_entries(table) == count);
+ cl_assert_equal_i(git_strmap_size(table), count);
}
void test_core_strmap__1(void)
diff --git a/tests/pack/sharing.c b/tests/pack/sharing.c
index f6f78ca03..ec18006c4 100644
--- a/tests/pack/sharing.c
+++ b/tests/pack/sharing.c
@@ -30,7 +30,7 @@ void test_pack_sharing__open_two_repos(void)
cl_assert_equal_i(2, pack->refcount.val);
}
- cl_assert_equal_i(3, git_strmap_num_entries(git__pack_cache));
+ cl_assert_equal_i(3, git_strmap_size(git__pack_cache));
git_object_free(obj1);
git_object_free(obj2);
@@ -38,5 +38,5 @@ void test_pack_sharing__open_two_repos(void)
git_repository_free(repo2);
/* we don't want to keep the packs open after the repos go away */
- cl_assert_equal_i(0, git_strmap_num_entries(git__pack_cache));
+ cl_assert_equal_i(0, git_strmap_size(git__pack_cache));
}