ucx/map.c

changeset 167
cecfbb5f8618
parent 110
53895e9a4bbb
child 168
6db9c5d7d7ff
--- 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;
 }

mercurial