Add g_hash_table_{remove,steal}_all to remove all nodes from a hash table.
authorMatthias Clasen <mclasen@redhat.com>
Thu, 1 Jun 2006 14:16:39 +0000 (14:16 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 1 Jun 2006 14:16:39 +0000 (14:16 +0000)
2006-06-01  Matthias Clasen  <mclasen@redhat.com>

* glib/glib.symbols:
* glib/ghash.h:
* glib/ghash.c: Add g_hash_table_{remove,steal}_all to
remove all nodes from a hash table.  (#168538, Matt Barnes)

ChangeLog
ChangeLog.pre-2-12
docs/reference/ChangeLog
docs/reference/glib/glib-sections.txt
glib/ghash.c
glib/ghash.h
glib/glib.symbols

index dd8dd06..c782756 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-06-01  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/glib.symbols: 
+       * glib/ghash.h: 
+       * glib/ghash.c: Add g_hash_table_{remove,steal}_all to
+       remove all nodes from a hash table.  (#168538, Matt Barnes)
+
 2006-06-01  Behdad Esfahbod  <behdad@gnome.org>
 
        * glib/gkeyfile.c (g_key_file_to_data),
index dd8dd06..c782756 100644 (file)
@@ -1,3 +1,10 @@
+2006-06-01  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/glib.symbols: 
+       * glib/ghash.h: 
+       * glib/ghash.c: Add g_hash_table_{remove,steal}_all to
+       remove all nodes from a hash table.  (#168538, Matt Barnes)
+
 2006-06-01  Behdad Esfahbod  <behdad@gnome.org>
 
        * glib/gkeyfile.c (g_key_file_to_data),
index 8f920ee..5b3db99 100644 (file)
@@ -1,3 +1,7 @@
+2006-06-01  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/glib-sections.txt: Add new hash table functions.
+
 Wed May 31 11:35:48 2006  Tim Janik  <timj@gtk.org>
 
        * gobject/tmpl/gtype.sgml (Note): amend G_TYPE_CHAR according to #303622.
index aa64591..14a5b96 100644 (file)
@@ -1844,6 +1844,8 @@ g_hash_table_remove
 g_hash_table_steal
 g_hash_table_foreach_remove
 g_hash_table_foreach_steal
+g_hash_table_remove_all
+g_hash_table_steal_all
 GHRFunc
 g_hash_table_freeze
 g_hash_table_thaw
index 2f4ac03..1069758 100644 (file)
@@ -215,21 +215,10 @@ g_hash_table_unref (GHashTable *hash_table)
 void
 g_hash_table_destroy (GHashTable *hash_table)
 {
-  gint i;
-  
   g_return_if_fail (hash_table != NULL);
   g_return_if_fail (hash_table->ref_count > 0);
   
-  for (i = 0; i < hash_table->size; i++)
-    {
-      g_hash_nodes_destroy (hash_table->nodes[i], 
-                            hash_table->key_destroy_func,
-                            hash_table->value_destroy_func);
-      hash_table->nodes[i] = NULL;
-    }
-  hash_table->nnodes = 0;
-  hash_table->size = HASH_TABLE_MIN_SIZE;
-
+  g_hash_table_remove_all (hash_table);
   g_hash_table_unref (hash_table);
 }
 
@@ -455,6 +444,38 @@ g_hash_table_remove (GHashTable       *hash_table,
 }
 
 /**
+ * g_hash_table_remove_all:
+ * @hash_table: a #GHashTable
+ *
+ * Removes all keys and their associated values from a #GHashTable.
+ *
+ * If the #GHashTable was created using g_hash_table_new_full(), the keys
+ * and values are freed using the supplied destroy functions, otherwise you
+ * have to make sure that any dynamically allocated values are freed
+ * yourself.
+ *
+ * Since: 2.12
+ **/
+void
+g_hash_table_remove_all (GHashTable *hash_table)
+{
+  guint i;
+
+  g_return_if_fail (hash_table != NULL);
+
+  for (i = 0; i < hash_table->size; i++)
+    {
+      g_hash_nodes_destroy (hash_table->nodes[i],
+                            hash_table->key_destroy_func,
+                            hash_table->value_destroy_func);
+      hash_table->nodes[i] = NULL;
+    }
+  hash_table->nnodes = 0;
+  
+  G_HASH_TABLE_RESIZE (hash_table);
+}
+
+/**
  * g_hash_table_steal:
  * @hash_table: a #GHashTable.
  * @key: the key to remove.
@@ -489,6 +510,33 @@ g_hash_table_steal (GHashTable    *hash_table,
 }
 
 /**
+ * g_hash_table_steal_all:
+ * @hash_table: a #GHashTable.
+ *
+ * Removes all keys and their associated values from a #GHashTable 
+ * without calling the key and value destroy functions.
+ *
+ * Since: 2.12
+ **/
+void
+g_hash_table_steal_all (GHashTable *hash_table)
+{
+  guint i;
+
+  g_return_if_fail (hash_table != NULL);
+
+  for (i = 0; i < hash_table->size; i++)
+    {
+      g_hash_nodes_destroy (hash_table->nodes[i], NULL, NULL);
+      hash_table->nodes[i] = NULL;
+    }
+
+  hash_table->nnodes = 0;
+
+  G_HASH_TABLE_RESIZE (hash_table);
+}
+
+/**
  * g_hash_table_foreach_remove:
  * @hash_table: a #GHashTable.
  * @func: the function to call for each key/value pair.
index 6d301b2..41813de 100644 (file)
@@ -54,8 +54,10 @@ void        g_hash_table_replace           (GHashTable     *hash_table,
                                            gpointer        value);
 gboolean    g_hash_table_remove                   (GHashTable     *hash_table,
                                            gconstpointer   key);
+void        g_hash_table_remove_all        (GHashTable     *hash_table);
 gboolean    g_hash_table_steal             (GHashTable     *hash_table,
                                            gconstpointer   key);
+void        g_hash_table_steal_all         (GHashTable     *hash_table);
 gpointer    g_hash_table_lookup                   (GHashTable     *hash_table,
                                            gconstpointer   key);
 gboolean    g_hash_table_lookup_extended   (GHashTable    *hash_table,
index 62e2a10..4c7b7c1 100644 (file)
@@ -362,9 +362,11 @@ g_hash_table_lookup_extended
 g_hash_table_new
 g_hash_table_new_full
 g_hash_table_remove
+g_hash_table_remove_all
 g_hash_table_replace
 g_hash_table_size
 g_hash_table_steal
+g_hash_table_steal_all
 #endif
 #endif