Function

GLibHashTableadd

since: 2.32

Declaration

gboolean
g_hash_table_add (
  GHashTable* hash_table,
  gpointer key
)

Description

This is a convenience function for using a GHashTable as a set. It is equivalent to calling g_hash_table_replace() with key as both the key and the value.

In particular, this means that if key already exists in the hash table, then the old copy of key in the hash table is freed and key replaces it in the table.

When a hash table only ever contains keys that have themselves as the corresponding value it is able to be stored more efficiently. See the discussion in the section description.

Starting from GLib 2.40, this function returns a boolean value to indicate whether the newly added value was already in the hash table or not.

Available since: 2.32

Parameters

hash_table

Type: GHashTable

A GHashTable.

The data is owned by the caller of the function.
key

Type: gpointer

A key to insert.

The argument can be NULL.
The called function takes ownership of the data, and is responsible for freeing it.

Return value

Type: gboolean

TRUE if the key did not exist yet.