more updates to ucx

Thu, 15 Oct 2015 15:01:50 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 15 Oct 2015 15:01:50 +0200
changeset 169
08adb4f87160
parent 168
6db9c5d7d7ff
child 170
cf054cded046

more updates to ucx

ucx/map.c file | annotate | diff | comparison | revisions
ucx/map.h file | annotate | diff | comparison | revisions
ucx/mempool.h file | annotate | diff | comparison | revisions
ucx/ucx.h file | annotate | diff | comparison | revisions
--- a/ucx/map.c	Thu Oct 15 12:46:09 2015 +0200
+++ b/ucx/map.c	Thu Oct 15 15:01:50 2015 +0200
@@ -82,6 +82,14 @@
     alfree(map->allocator, map);
 }
 
+void ucx_map_free_content(UcxMap *map, ucx_destructor destr) {
+    UcxMapIterator iter = ucx_map_iterator(map);
+    void *val;
+    UCX_MAP_FOREACH(key, val, iter) {
+        destr(val);
+    }
+}
+
 void ucx_map_clear(UcxMap *map) {
     if (map->count == 0) {
         return; // nothing to do
--- a/ucx/map.h	Thu Oct 15 12:46:09 2015 +0200
+++ b/ucx/map.h	Thu Oct 15 15:01:50 2015 +0200
@@ -146,22 +146,44 @@
 /**
  * Frees a hash map.
  * 
- * <b>Note:</b> the contents are <b>not</b> freed, use an UcxMempool for that
- * purpose.
+ * <b>Note:</b> the contents are <b>not</b> freed, use ucx_map_free_content()
+ * before calling this function to achieve that.
  * 
  * @param map the map to be freed
+ * @see ucx_map_free_content()
  */
 void ucx_map_free(UcxMap *map);
 
 /**
+ * Frees the contents of a hash map.
+ * 
+ * This is a convenience function that iterates over the map and passes all
+ * values to the specified destructor function (e.g. stdlib free()).
+ * 
+ * You must ensure, that it is valid to pass each value in the map to the same
+ * destructor function.
+ * 
+ * You should free or clear the map afterwards, as the contents will be invalid.
+ * 
+ * @param map for which the contents shall be freed
+ * @param destr pointer to the destructor function
+ * @see ucx_map_free()
+ * @see ucx_map_clear()
+ */
+void ucx_map_free_content(UcxMap *map, ucx_destructor destr);
+
+/**
  * Clears a hash map.
  * 
- * <b>Note:</b> the contents are <b>not</b> freed.
+ * <b>Note:</b> the contents are <b>not</b> freed, use ucx_map_free_content()
+ * before calling this function to achieve that.
  * 
- * @param map the map to be freed
+ * @param map the map to be cleared
+ * @see ucx_map_free_content()
  */
 void ucx_map_clear(UcxMap *map);
 
+
 /**
  * Copies contents from a map to another map using a copy function.
  * 
--- a/ucx/mempool.h	Thu Oct 15 12:46:09 2015 +0200
+++ b/ucx/mempool.h	Thu Oct 15 15:01:50 2015 +0200
@@ -47,13 +47,6 @@
 #endif
 
 /**
- * A function pointer to a destructor function.
- * @see ucx_mempool_setdestr()
- * @see ucx_mempool_regdestr()
- */
-typedef void(*ucx_destructor)(void*);
-
-/**
  * UCX mempool structure.
  */
 typedef struct {
--- a/ucx/ucx.h	Thu Oct 15 12:46:09 2015 +0200
+++ b/ucx/ucx.h	Thu Oct 15 15:01:50 2015 +0200
@@ -70,6 +70,14 @@
 /** Pointless in C. */
 #define UCX_EXTERN
 #endif
+    
+
+/**
+ * A function pointer to a destructor function.
+ * @see ucx_mempool_setdestr()
+ * @see ucx_mempool_regdestr()
+ */
+typedef void(*ucx_destructor)(void*);
 
 /**
  * Function pointer to a compare function.

mercurial