mirror of
				https://github.com/theoludwig/libcproject.git
				synced 2025-05-21 23:21:15 +02:00 
			
		
		
		
	feat: add hash_map_free
This commit is contained in:
		| @@ -217,3 +217,12 @@ string_t *hash_map_get_keys(struct hash_map *hash_map) { | ||||
|   } | ||||
|   return keys; | ||||
| } | ||||
|  | ||||
| void hash_map_free(struct hash_map *hash_map) { | ||||
|   for (size_t index = 0; index < hash_map->capacity; index++) { | ||||
|     if (hash_map->items[index] != NULL) { | ||||
|       linked_list_free(hash_map->items[index]); | ||||
|     } | ||||
|   } | ||||
|   free(hash_map); | ||||
| } | ||||
|   | ||||
| @@ -89,4 +89,10 @@ bool hash_map_contains_key(struct hash_map *hash_map, string_t key); | ||||
|  */ | ||||
| string_t *hash_map_get_keys(struct hash_map *hash_map); | ||||
|  | ||||
| /** | ||||
|  * @brief Frees the hash map. | ||||
|  * @since v2.1.0 | ||||
|  */ | ||||
| void hash_map_free(struct hash_map *hash_map); | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -92,5 +92,6 @@ void linked_list_free(struct linked_list *list) { | ||||
|     node_current = node_current->next; | ||||
|     free(node_to_remove); | ||||
|   } | ||||
|   list->head = NULL; | ||||
|   free(list); | ||||
| } | ||||
|   | ||||
| @@ -285,6 +285,7 @@ bool string_get_has_unique_characters(const string_t string_value) { | ||||
|       hash_map_add(characters_already_seen, key, (void*)true); | ||||
|     } | ||||
|   } | ||||
|   hash_map_free(characters_already_seen); | ||||
|   return has_unique; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -24,4 +24,5 @@ void hash_map_test() { | ||||
|   hash_map_remove(hash_map, "key5"); | ||||
|   assert(hash_map->length == 5); | ||||
|   assert(!hash_map_contains_key(hash_map, "key5")); | ||||
|   hash_map_free(hash_map); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user