git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/5] hashmap: add enum for hashmap free_entries option

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
Jun 5, 2014, 06:06 UTC
Message-ID
<20140605060640.GB23874@sandbox-ub>
In-Reply-To
<20140605060425.GA23874@sandbox-ub>

This allows a reader to immediately know which options can be used and what this parameter is about.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
 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
Previous: Heiko VoigtNext: Karsten Blees
Message 2 of 26 in “submodule config lookup API”
  1. 0/5 submodule config lookup APIHeiko Voigt, Jun 5, 2014
  2. 1/5 hashmap: add enum for hashmap free_entries optionHeiko Voigt, Jun 5, 2014
  3. Karsten BleesJun 6, 2014
  4. Heiko VoigtJun 10, 2014
  5. Karsten BleesJun 11, 2014
  6. Junio C HamanoJun 12, 2014
  7. Karsten BleesJun 17, 2014
  8. Heiko VoigtJun 17, 2014
  9. Junio C HamanoJun 17, 2014
  10. 2/5 implement submodule config cache for lookup of submodule namesHeiko Voigt, Jun 5, 2014
  11. W. Trevor KingJun 5, 2014
  12. Heiko VoigtJun 6, 2014
  13. Eric SunshineJun 8, 2014
  14. Heiko VoigtJun 10, 2014
  15. Junio C HamanoJun 12, 2014
  16. Heiko VoigtJun 13, 2014
  17. 3/5 extract functions for submodule config set and lookupHeiko Voigt, Jun 5, 2014
  18. 4/5 use new config API for worktree configurations of submodulesHeiko Voigt, Jun 5, 2014
  19. 5/5 do not die on error of parsing fetchrecursesubmodules optionHeiko Voigt, Jun 5, 2014
  20. Junio C HamanoJun 12, 2014
  21. Heiko VoigtJun 13, 2014
  22. Junio C HamanoJun 16, 2014
  23. Heiko VoigtJun 17, 2014
  24. Junio C HamanoJun 12, 2014
  25. Jens LehmannJun 13, 2014
  26. Junio C HamanoJun 13, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.