/** * g_hash_table_replace: * @hash_table: a #GHashTable. * @key: a key to insert. * @value: the value to associate with the key. * * Inserts a new key and value into a #GHashTable similar to * g_hash_table_insert(). The difference is that if the key already exists * in the #GHashTable, it gets replaced by the new key. If you supplied a * @value_destroy_func when creating the #GHashTable, the old value is freed * using that function. If you supplied a @key_destroy_func when creating the * #GHashTable, the old key is freed using that function. **/ void g_hash_table_replace (GHashTable *hash_table, gpointer key, gpointer value) { GHashNode **node; g_return_if_fail (hash_table != NULL); node = g_hash_table_lookup_node (hash_table, key); if (*node) { if (hash_table->key_destroy_func) hash_table->key_destroy_func ((*node)->key); if (hash_table->value_destroy_func) hash_table->value_destroy_func ((*node)->value); (*node)->key = key; (*node)->value = value; } else { *node = g_hash_node_new (key, value); hash_table->nnodes++; G_HASH_TABLE_RESIZE (hash_table); } }
void g_hash_table_insert (GHashTable *hash_table, gpointer key, gpointer value) { GHashNode **node; node = g_hash_table_lookup_node (hash_table, key); if (*node) { /* free the passed key */ if (hash_table->key_destroy_func) hash_table->key_destroy_func (key); if (hash_table->value_destroy_func) hash_table->value_destroy_func ((*node)->value); (*node)->value = value; } else { *node = g_hash_node_new (key, value); hash_table->nnodes++; } }
/** * g_hash_table_insert: * @hash_table: a #GHashTable. * @key: a key to insert. * @value: the value to associate with the key. * * Inserts a new key and value into a #GHashTable. * * If the key already exists in the #GHashTable its current value is replaced * with the new value. If you supplied a @value_destroy_func when creating the * #GHashTable, the old value is freed using that function. If you supplied * a @key_destroy_func when creating the #GHashTable, the passed key is freed * using that function. **/ void g_hash_table_insert (GHashTable *hash_table, gpointer key, gpointer value) { GHashNode **node; g_return_if_fail (hash_table != NULL); node = g_hash_table_lookup_node (hash_table, key); if (*node) { /* do not reset node->key in this place, keeping * the old key is the intended behaviour. * g_hash_table_replace() can be used instead. */ /* free the passed key */ if (hash_table->key_destroy_func) hash_table->key_destroy_func (key); if (hash_table->value_destroy_func) hash_table->value_destroy_func ((*node)->value); (*node)->value = value; } else { *node = g_hash_node_new (key, value); hash_table->nnodes++; G_HASH_TABLE_RESIZE (hash_table); } }
/** * g_hash_table_replace: * @hash_table: a #GHashTable. * @key: a key to insert. * @value: the value to associate with the key. * * Inserts a new key and value into a #GHashTable similar to * g_hash_table_insert(). The difference is that if the key already exists * in the #GHashTable, it gets replaced by the new key. If you supplied a * @value_destroy_func when creating the #GHashTable, the old value is freed * using that function. If you supplied a @key_destroy_func when creating the * #GHashTable, the old key is freed using that function. **/ void mono_g_hash_table_replace (MonoGHashTable *hash_table, gpointer key, gpointer value) { MonoGHashNode **node; g_return_if_fail (hash_table != NULL); node = g_hash_table_lookup_node (hash_table, key); if (*node) { if (hash_table->key_destroy_func) hash_table->key_destroy_func ((*node)->key); if (hash_table->value_destroy_func) hash_table->value_destroy_func ((*node)->value); SET_NODE_KEY ((*node), hash_table->gc_type, key); SET_NODE_VALUE ((*node), hash_table->gc_type, value); } else { *node = g_hash_node_new (key, value, hash_table->gc_type); hash_table->nnodes++; G_HASH_TABLE_RESIZE (hash_table); } }