Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / libpspp / hmap.c
index 081d7cbba5a5f3e607f6a0dc3bfb90176a796a06..4436f8dfca1375f89ced27f907a2cdeeb2b52111 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010, 2011 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
 #include <config.h>
 #endif
 
-#include <libpspp/hmap.h>
+#include "libpspp/hmap.h"
+
 #include <assert.h>
 #include <stdlib.h>
 
+#include "gl/xalloc.h"
+
 static size_t capacity_to_mask (size_t capacity);
 
 /* Initializes MAP as a new hash map that is initially empty. */
@@ -47,6 +50,18 @@ hmap_swap (struct hmap *a, struct hmap *b)
     b->buckets = &b->one;
 }
 
+/* Removes all of the elements from MAP, without destroying MAP itself and
+   without accessing the existing elements (if any). */
+void
+hmap_clear (struct hmap *map)
+{
+  size_t i;
+
+  for (i = 0; i <= map->mask; i++)
+    map->buckets[i] = NULL;
+  map->count = 0;
+}
+
 /* Frees the memory, if any, allocated by hash map MAP.  This has
    no effect on the actual data items in MAP, if any, because the
    client is responsible for allocating and freeing them.  It
@@ -75,7 +90,7 @@ hmap_rehash (struct hmap *map, size_t new_mask)
 
   assert ((new_mask & (new_mask + 1)) == 0);
   if (new_mask)
-    new_buckets = calloc (new_mask + 1, sizeof *new_buckets);
+    new_buckets = xcalloc (new_mask + 1, sizeof *new_buckets);
   else 
     {
       new_buckets = &map->one;