Add g_hash_table_{remove,steal}_all to remove all nodes from a hash table.

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)
This commit is contained in:
Matthias Clasen 2006-06-01 14:16:39 +00:00 committed by Matthias Clasen
parent 38b53eed54
commit a5b4b8bfb1
7 changed files with 84 additions and 12 deletions

View 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),

View 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),

View 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.

View 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

View 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);
}
@ -454,6 +443,38 @@ g_hash_table_remove (GHashTable *hash_table,
return FALSE;
}
/**
* 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.
@ -488,6 +509,33 @@ g_hash_table_steal (GHashTable *hash_table,
return FALSE;
}
/**
* 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.

View 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,

View 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