/* * g_hash_table_foreach_remove_or_steal: * @hash_table: our #GHashTable * @func: the user's callback function * @user_data: data for @func * @notify: %TRUE if the destroy notify handlers are to be called * * Implements the common logic for g_hash_table_foreach_remove() and * g_hash_table_foreach_steal(). * * Iterates over every node in the table, calling @func with the key * and value of the node (and @user_data). If @func returns %TRUE the * node is removed from the table. * * If @notify is true then the destroy notify handlers will be called * for each removed node. */ static guint g_hash_table_foreach_remove_or_steal (GHashTable *hash_table, GHRFunc func, gpointer user_data, gboolean notify) { GHashNode *node, **node_ptr; guint deleted = 0; gint i; for (i = 0; i < hash_table->size; i++) for (node_ptr = &hash_table->nodes[i]; (node = *node_ptr) != NULL;) if ((* func) (node->key, node->value, user_data)) { g_hash_table_remove_node (hash_table, &node_ptr, notify); deleted++; } else node_ptr = &node->next; g_hash_table_maybe_resize (hash_table); #ifndef G_DISABLE_ASSERT if (deleted > 0) hash_table->version++; #endif return deleted; }
/* * g_hash_table_foreach_remove_or_steal: * @hash_table: our #GHashTable * @func: the user's callback function * @user_data: data for @func * @notify: %TRUE if the destroy notify handlers are to be called * * Implements the common logic for g_hash_table_foreach_remove() and * g_hash_table_foreach_steal(). * * Iterates over every node in the table, calling @func with the key * and value of the node (and @user_data). If @func returns %TRUE the * node is removed from the table. * * If @notify is true then the destroy notify handlers will be called * for each removed node. */ static guint g_hash_table_foreach_remove_or_steal (GHashTable *hash_table, GHRFunc func, gpointer user_data, gboolean notify) { guint deleted = 0; gint i; for (i = 0; i < hash_table->size; i++) { GHashNode *node = &hash_table->nodes [i]; if (node->key_hash > 1 && (* func) (node->key, node->value, user_data)) { g_hash_table_remove_node (hash_table, node, notify); deleted++; } } g_hash_table_maybe_resize (hash_table); #ifndef G_DISABLE_ASSERT if (deleted > 0) hash_table->version++; #endif return deleted; }
/* * g_hash_table_remove_internal: * @hash_table: our #GHashTable * @key: the key to remove * @notify: %TRUE if the destroy notify handlers are to be called * Return value: %TRUE if a node was found and removed, else %FALSE * * Implements the common logic for the g_hash_table_remove() and * g_hash_table_steal() functions. * * Do a lookup of @key and remove it if it is found, calling the * destroy notify handlers only if @notify is %TRUE. */ static gboolean g_hash_table_remove_internal (GHashTable *hash_table, gconstpointer key, gboolean notify) { GHashNode *node; guint node_index; g_return_val_if_fail (hash_table != NULL, FALSE); node_index = g_hash_table_lookup_node (hash_table, key); node = &hash_table->nodes [node_index]; /* g_hash_table_lookup_node() never returns a tombstone, so this is safe */ if (!node->key_hash) return FALSE; g_hash_table_remove_node (hash_table, node, notify); g_hash_table_maybe_resize (hash_table); #ifndef G_DISABLE_ASSERT hash_table->version++; #endif return TRUE; }
/* * g_hash_table_remove_all_nodes: * @hash_table: our #GHashTable * @notify: %TRUE if the destroy notify handlers are to be called * * Removes all nodes from the table. Since this may be a precursor to * freeing the table entirely, no resize is performed. * * If @notify is %TRUE then the destroy notify functions are called * for the key and value of the hash node. */ static void g_hash_table_remove_all_nodes (GHashTable *hash_table, gboolean notify) { GHashNode **node_ptr; int i; for (i = 0; i < hash_table->size; i++) for (node_ptr = &hash_table->nodes[i]; *node_ptr != NULL;) g_hash_table_remove_node (hash_table, &node_ptr, notify); hash_table->nnodes = 0; }
static void iter_remove_or_steal (RealIter *ri, gboolean notify) { g_return_if_fail (ri != NULL); #ifndef G_DISABLE_ASSERT g_return_if_fail (ri->version == ri->hash_table->version); #endif g_return_if_fail (ri->position >= 0); g_return_if_fail (ri->position < ri->hash_table->size); g_hash_table_remove_node (ri->hash_table, &ri->hash_table->nodes [ri->position], notify); #ifndef G_DISABLE_ASSERT ri->version++; ri->hash_table->version++; #endif }
/* * g_hash_table_remove_internal: * @hash_table: our #GHashTable * @key: the key to remove * @notify: %TRUE if the destroy notify handlers are to be called * Return value: %TRUE if a node was found and removed, else %FALSE * * Implements the common logic for the g_hash_table_remove() and * g_hash_table_steal() functions. * * Do a lookup of @key and remove it if it is found, calling the * destroy notify handlers only if @notify is %TRUE. */ static gboolean g_hash_table_remove_internal (GHashTable *hash_table, gconstpointer key, gboolean notify) { GHashNode **node_ptr; g_return_val_if_fail (hash_table != NULL, FALSE); node_ptr = g_hash_table_lookup_node (hash_table, key, NULL); if (*node_ptr == NULL) return FALSE; g_hash_table_remove_node (hash_table, &node_ptr, notify); g_hash_table_maybe_resize (hash_table); #ifndef G_DISABLE_ASSERT hash_table->version++; #endif return TRUE; }
/* * g_hash_table_foreach_remove_or_steal: * @hash_table: our #GHashTable * @func: the user's callback function * @user_data: data for @func * @notify: %TRUE if the destroy notify handlers are to be called * * Implements the common logic for g_hash_table_foreach_remove() and * g_hash_table_foreach_steal(). * * Iterates over every node in the table, calling @func with the key * and value of the node (and @user_data). If @func returns %TRUE the * node is removed from the table. * * If @notify is true then the destroy notify handlers will be called * for each removed node. */ static guint g_hash_table_foreach_remove_or_steal (GHashTable *hash_table, GHRFunc func, gpointer user_data, gboolean notify) { guint deleted = 0; gint i; #ifndef G_DISABLE_ASSERT gint version = hash_table->version; #endif for (i = 0; i < hash_table->size; i++) { guint node_hash = hash_table->hashes[i]; gpointer node_key = hash_table->keys[i]; gpointer node_value = hash_table->values[i]; if (HASH_IS_REAL (node_hash) && (* func) (node_key, node_value, user_data)) { g_hash_table_remove_node (hash_table, i, notify); deleted++; } #ifndef G_DISABLE_ASSERT g_return_val_if_fail (version == hash_table->version, 0); #endif } g_hash_table_maybe_resize (hash_table); #ifndef G_DISABLE_ASSERT if (deleted > 0) hash_table->version++; #endif return deleted; }
/* * g_hash_table_remove_internal: * @hash_table: our #GHashTable * @key: the key to remove * @notify: %TRUE if the destroy notify handlers are to be called * Return value: %TRUE if a node was found and removed, else %FALSE * * Implements the common logic for the g_hash_table_remove() and * g_hash_table_steal() functions. * * Do a lookup of @key and remove it if it is found, calling the * destroy notify handlers only if @notify is %TRUE. */ static gboolean g_hash_table_remove_internal (GHashTable *hash_table, gconstpointer key, gboolean notify) { guint node_index; guint node_hash; g_return_val_if_fail (hash_table != NULL, FALSE); node_index = g_hash_table_lookup_node (hash_table, key, &node_hash); if (!HASH_IS_REAL (hash_table->hashes[node_index])) return FALSE; g_hash_table_remove_node (hash_table, node_index, notify); g_hash_table_maybe_resize (hash_table); #ifndef G_DISABLE_ASSERT hash_table->version++; #endif return TRUE; }