updated UcxMap implementation

Thu, 15 Oct 2015 12:37:01 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 Oct 2015 12:37:01 +0200
changeset 167
cecfbb5f8618
parent 166
8911170d5e78
child 168
6db9c5d7d7ff

updated UcxMap implementation

ucx/map.c file | annotate | diff | comparison | revisions
ucx/map.h file | annotate | diff | comparison | revisions
--- a/ucx/map.c	Thu Oct 15 11:41:06 2015 +0200
+++ b/ucx/map.c	Thu Oct 15 12:37:01 2015 +0200
@@ -62,7 +62,7 @@
     return map;
 }
 
-static void ucx_map_free_elmlist(UcxMap *map) {
+static void ucx_map_free_elmlist_contents(UcxMap *map) {
     for (size_t n = 0 ; n < map->size ; n++) {
         UcxMapElement *elem = map->map[n];
         if (elem != NULL) {
@@ -74,14 +74,20 @@
             } while (elem != NULL);
         }
     }
-    alfree(map->allocator, map->map);
 }
 
 void ucx_map_free(UcxMap *map) {
-    ucx_map_free_elmlist(map);
+    ucx_map_free_elmlist_contents(map);
+    alfree(map->allocator, map->map);
     alfree(map->allocator, map);
 }
 
+void ucx_map_clear(UcxMap *map) {
+    ucx_map_free_elmlist_contents(map);
+    memset(map->map, 0, map->size*sizeof(UcxMapElement*));
+    map->count = 0;
+}
+
 int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to,
         copy_func fnc, void *data) {
     UcxMapIterator i = ucx_map_iterator(from);
@@ -124,7 +130,8 @@
         ucx_map_copy(&oldmap, map, NULL, NULL);
         
         /* free the UcxMapElement list of oldmap */
-        ucx_map_free_elmlist(&oldmap);
+        ucx_map_free_elmlist_contents(&oldmap);
+        alfree(map->allocator, oldmap.map);
     }
     return 0;
 }
--- a/ucx/map.h	Thu Oct 15 11:41:06 2015 +0200
+++ b/ucx/map.h	Thu Oct 15 12:37:01 2015 +0200
@@ -154,6 +154,15 @@
 void ucx_map_free(UcxMap *map);
 
 /**
+ * Clears a hash map.
+ * 
+ * <b>Note:</b> the contents are <b>not</b> freed.
+ * 
+ * @param map the map to be freed
+ */
+void ucx_map_clear(UcxMap *map);
+
+/**
  * Copies contents from a map to another map using a copy function.
  * 
  * <b>Note:</b> The destination map does not need to be empty. However, if it

mercurial