hmapx: New function hmapx_clear().
[pspp] / src / libpspp / hmapx.c
index 437b2bdba5a7aad4ad301f672fc3681b5f2010fd..25dabf6eda54184085509a9be4f807eb2714a87e 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,9 +18,9 @@
 #include <config.h>
 #endif
 
-#include <libpspp/hmapx.h>
+#include "libpspp/hmapx.h"
 #include <stdlib.h>
-#include "xalloc.h"
+#include "gl/xalloc.h"
 
 /* Frees the memory, if any, allocated by hash map MAP, including
    all hmapx_nodes that it contains.  The user-defined data items
@@ -45,6 +45,18 @@ hmapx_destroy (struct hmapx *map)
     }
 }
 
+/* Removes all hmapx_nodes from MAP and frees them.  The user-defined data
+   items that the hmapx_nodes point to are not affected. */
+void
+hmapx_clear (struct hmapx *map)
+{
+  struct hmapx_node *node, *next;
+  void *data;
+
+  HMAPX_FOR_EACH_SAFE (data, node, next, map)
+    hmapx_delete (map, node);
+}
+
 /* Allocates and returns a new hmapx_node with DATA as its data
    item. */
 static struct hmapx_node *