Commit 7e926ef3 by Patrick Steinhardt

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.
parent 351eeff3
...@@ -37,7 +37,7 @@ void git_offmap_clear(git_offmap *map) ...@@ -37,7 +37,7 @@ void git_offmap_clear(git_offmap *map)
kh_clear(off, 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); return kh_size(map);
} }
......
...@@ -44,7 +44,13 @@ void git_offmap_free(git_offmap *map); ...@@ -44,7 +44,13 @@ void git_offmap_free(git_offmap *map);
*/ */
void git_offmap_clear(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); 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_valid_index(git_offmap *map, size_t idx);
......
...@@ -44,6 +44,12 @@ void git_oidmap_free(git_oidmap *map); ...@@ -44,6 +44,12 @@ void git_oidmap_free(git_oidmap *map);
*/ */
void git_oidmap_clear(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_size(git_oidmap *map);
size_t git_oidmap_lookup_index(git_oidmap *map, const git_oid *key); size_t git_oidmap_lookup_index(git_oidmap *map, const git_oid *key);
......
...@@ -36,7 +36,7 @@ void git_strmap_clear(git_strmap *map) ...@@ -36,7 +36,7 @@ void git_strmap_clear(git_strmap *map)
kh_clear(str, 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); return kh_size(map);
} }
......
...@@ -42,7 +42,13 @@ void git_strmap_free(git_strmap *map); ...@@ -42,7 +42,13 @@ void git_strmap_free(git_strmap *map);
*/ */
void git_strmap_clear(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); 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_valid_index(git_strmap *map, size_t idx);
......
...@@ -625,7 +625,7 @@ int git_submodule_foreach( ...@@ -625,7 +625,7 @@ int git_submodule_foreach(
goto done; goto done;
if (!(error = git_vector_init( 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, { git_strmap_foreach_value(submodules, sm, {
if ((error = git_vector_insert(&snapshot, sm)) < 0) if ((error = git_vector_insert(&snapshot, sm)) < 0)
......
...@@ -344,7 +344,7 @@ unsigned int git_treebuilder_entrycount(git_treebuilder *bld) ...@@ -344,7 +344,7 @@ unsigned int git_treebuilder_entrycount(git_treebuilder *bld)
{ {
assert(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) 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 ...@@ -811,7 +811,7 @@ int git_treebuilder_write_with_buffer(git_oid *oid, git_treebuilder *bld, git_bu
git_buf_clear(tree); 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) if ((error = git_vector_init(&entries, entrycount, entry_sort_cmp)) < 0)
goto out; goto out;
......
...@@ -16,12 +16,13 @@ void test_core_strmap__cleanup(void) ...@@ -16,12 +16,13 @@ void test_core_strmap__cleanup(void)
void test_core_strmap__0(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; char *str;
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
...@@ -38,7 +39,7 @@ static void insert_strings(git_strmap *table, int count) ...@@ -38,7 +39,7 @@ static void insert_strings(git_strmap *table, int count)
cl_assert(err >= 0); 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) void test_core_strmap__1(void)
......
...@@ -30,7 +30,7 @@ void test_pack_sharing__open_two_repos(void) ...@@ -30,7 +30,7 @@ void test_pack_sharing__open_two_repos(void)
cl_assert_equal_i(2, pack->refcount.val); 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(obj1);
git_object_free(obj2); git_object_free(obj2);
...@@ -38,5 +38,5 @@ void test_pack_sharing__open_two_repos(void) ...@@ -38,5 +38,5 @@ void test_pack_sharing__open_two_repos(void)
git_repository_free(repo2); git_repository_free(repo2);
/* we don't want to keep the packs open after the repos go away */ /* 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));
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment