[PATCH 1/5] hashmap: add enum for hashmap free_entries option
From: Heiko Voigt <hidden>
Date: 2016-06-15 23:01:29
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
This allows a reader to immediately know which options can be used and what this parameter is about. Signed-off-by: Heiko Voigt <redacted> --- Documentation/technical/api-hashmap.txt | 2 +- diffcore-rename.c | 2 +- hashmap.c | 2 +- hashmap.h | 8 +++++++- name-hash.c | 4 ++-- test-hashmap.c | 6 +++--- 6 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/Documentation/technical/api-hashmap.txt b/Documentation/technical/api-hashmap.txt
index b977ae8..b04bb40 100644
--- a/Documentation/technical/api-hashmap.txt
+++ b/Documentation/technical/api-hashmap.txt@@ -187,7 +187,7 @@ void long2double_init(void) void long2double_free(void) { - hashmap_free(&map, 1); + hashmap_free(&map, HASHMAP_FREE_ENTRIES); } static struct long2double *find_entry(long key)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 749a35d..f30239a 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c@@ -335,7 +335,7 @@ static int find_exact_renames(struct diff_options *options) renames += find_identical_files(&file_table, i, options); /* Free the hash data structure and entries */ - hashmap_free(&file_table, 1); + hashmap_free(&file_table, HASHMAP_FREE_ENTRIES); return renames; }
diff --git a/hashmap.c b/hashmap.c
index d1b8056..9a3555a 100644
--- a/hashmap.c
+++ b/hashmap.c@@ -135,7 +135,7 @@ void hashmap_init(struct hashmap *map, hashmap_cmp_fn equals_function, alloc_table(map, size); } -void hashmap_free(struct hashmap *map, int free_entries) +void hashmap_free(struct hashmap *map, enum hashmap_free_options free_entries) { if (!map || !map->table) return;
diff --git a/hashmap.h b/hashmap.h
index a816ad4..6c558df 100644
--- a/hashmap.h
+++ b/hashmap.h@@ -1,6 +1,11 @@ #ifndef HASHMAP_H #define HASHMAP_H +enum hashmap_free_options { + HASHMAP_NO_FREE_ENTRIES = 0, + HASHMAP_FREE_ENTRIES = 1, +}; + /* * Generic implementation of hash-based key-value mappings. * See Documentation/technical/api-hashmap.txt.
@@ -39,7 +44,8 @@ struct hashmap_iter { extern void hashmap_init(struct hashmap *map, hashmap_cmp_fn equals_function, size_t initial_size); -extern void hashmap_free(struct hashmap *map, int free_entries); +extern void hashmap_free(struct hashmap *map, + enum hashmap_free_options free_entries); /* hashmap_entry functions */
diff --git a/name-hash.c b/name-hash.c
index 97444d0..be7c4ae 100644
--- a/name-hash.c
+++ b/name-hash.c@@ -233,6 +233,6 @@ void free_name_hash(struct index_state *istate) return; istate->name_hash_initialized = 0; - hashmap_free(&istate->name_hash, 0); - hashmap_free(&istate->dir_hash, 1); + hashmap_free(&istate->name_hash, HASHMAP_NO_FREE_ENTRIES); + hashmap_free(&istate->dir_hash, HASHMAP_FREE_ENTRIES); }
diff --git a/test-hashmap.c b/test-hashmap.c
index f5183fb..ac8d6a2 100644
--- a/test-hashmap.c
+++ b/test-hashmap.c@@ -100,7 +100,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) hashmap_add(&map, entries[i]); } - hashmap_free(&map, 0); + hashmap_free(&map, HASHMAP_NO_FREE_ENTRIES); } } else { /* test map lookups */
@@ -121,7 +121,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) } } - hashmap_free(&map, 0); + hashmap_free(&map, HASHMAP_NO_FREE_ENTRIES); } }
@@ -250,6 +250,6 @@ int main(int argc, char *argv[]) } } - hashmap_free(&map, 1); + hashmap_free(&map, HASHMAP_FREE_ENTRIES); return 0; }
--
2.0.0