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.
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
diff --git a/src/offmap.c b/src/offmap.c
index d4388ca..2b447b3 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 1280fd3..cde6c31 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 733357f..c44f722 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 98b939f..a213228 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 5a43c66..1b7f1a4 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 e11b544..72921fa 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 9134451..cc6f93d 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 e19ceae..d6af977 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 f6f78ca..ec18006 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));
}