GLib.HashTable
Description: Reference for GLib.HashTable

### Struct

# GLibHashTable

since: 2.0

#### Description

    struct GHashTable {
      /* No available fields */
    }

The `GHashTable` struct is an opaque data structure to represent a [Hash Table][glib-Hash-Tables]. It should only be accessed via the following functions.

Available since: 2.0

#### Functions

###### g_hash_table_add

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.

since: 2.32

###### g_hash_table_contains

Checks if `key` is in `hash_table`.

since: 2.32

###### g_hash_table_destroy

Destroys all keys and values in the `GHashTable` and decrements its reference count by 1. If keys and/or values are dynamically allocated, you should either free them first or create the `GHashTable` with destroy notifiers using g_hash_table_new_full(). In the latter case the destroy functions you supplied will be called on all keys and values during the destruction phase.

since: 2.0

###### g_hash_table_find

Calls the given function for key/value pairs in the `GHashTable` until `predicate` returns `TRUE`. The function is passed the key and value of each pair, and the given `user_data` parameter. The hash table may not be modified while iterating over it (you can’t add/remove items).

since: 2.4

###### g_hash_table_foreach

Calls the given function for each of the key/value pairs in the `GHashTable`. The function is passed the key and value of each pair, and the given `user_data` parameter. The hash table may not be modified while iterating over it (you can’t add/remove items). To remove all items matching a predicate, use g_hash_table_foreach_remove().

since: 2.0

###### g_hash_table_foreach_remove

Calls the given function for each key/value pair in the `GHashTable`. If the function returns `TRUE`, then the key/value pair is removed from the `GHashTable`. If you supplied key or value destroy functions when creating the `GHashTable`, they are used to free the memory allocated for the removed keys and values.

since: 2.0

###### g_hash_table_foreach_steal

Calls the given function for each key/value pair in the `GHashTable`. If the function returns `TRUE`, then the key/value pair is removed from the `GHashTable`, but no key or value destroy functions are called.

since: 2.0

###### g_hash_table_get_keys

Retrieves every key inside `hash_table`. The returned data is valid until changes to the hash release those keys.

since: 2.14

###### g_hash_table_get_keys_as_array

Retrieves every key inside `hash_table`, as an array.

since: 2.40

###### g_hash_table_get_keys_as_ptr_array

Retrieves every key inside `hash_table`, as a `GPtrArray`. The returned data is valid until changes to the hash release those keys.

since: 2.76

###### g_hash_table_get_values

Retrieves every value inside `hash_table`. The returned data is valid until `hash_table` is modified.

since: 2.14

###### g_hash_table_get_values_as_ptr_array

Retrieves every value inside `hash_table`, as a `GPtrArray`. The returned data is valid until changes to the hash release those values.

since: 2.76

###### g_hash_table_insert

Inserts a new key and value into a `GHashTable`.

since: 2.0

###### g_hash_table_lookup

Looks up a key in a `GHashTable`. Note that this function cannot distinguish between a key that is not present and one which is present and has the value `NULL`. If you need this distinction, use g_hash_table_lookup_extended().

since: 2.0

###### g_hash_table_lookup_extended

Looks up a key in the `GHashTable`, returning the original key and the associated value and a #gboolean which is `TRUE` if the key was found. This is useful if you need to free the memory allocated for the original key, for example before calling g_hash_table_remove().

since: 2.0

###### g_hash_table_new

Creates a new `GHashTable` with a reference count of 1.

since: 2.0

###### g_hash_table_new_full

Creates a new `GHashTable` like `g_hash_table_new()` with a reference count of 1 and allows to specify functions to free the memory allocated for the key and value that get called when removing the entry from the `GHashTable`.

since: 2.0

###### g_hash_table_new_similar

Creates a new `GHashTable` like `g_hash_table_new_full()` with a reference count of 1.

since: 2.72

###### g_hash_table_ref

Atomically increments the reference count of `hash_table` by one. This function is MT-safe and may be called from any thread.

since: 2.10

###### g_hash_table_remove

Removes a key and its associated value from a `GHashTable`.

since: 2.0

###### g_hash_table_remove_all

Removes all keys and their associated values from a `GHashTable`.

since: 2.12

###### g_hash_table_replace

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.

since: 2.0

###### g_hash_table_size

Returns the number of elements contained in the `GHashTable`.

since: 2.0

###### g_hash_table_steal

Removes a key and its associated value from a `GHashTable` without calling the key and value destroy functions.

since: 2.0

###### g_hash_table_steal_all

Removes all keys and their associated values from a `GHashTable` without calling the key and value destroy functions.

since: 2.12

###### g_hash_table_steal_all_keys

Removes all keys and their associated values from a `GHashTable` without calling the key destroy functions, returning the keys as a `GPtrArray` with the free func set to the `hash_table` key destroy function.

since: 2.76

###### g_hash_table_steal_all_values

Removes all keys and their associated values from a `GHashTable` without calling the value destroy functions, returning the values as a `GPtrArray` with the free func set to the `hash_table` value destroy function.

since: 2.76

###### g_hash_table_steal_extended

Looks up a key in the `GHashTable`, stealing the original key and the associated value and returning `TRUE` if the key was found. If the key was not found, `FALSE` is returned.

since: 2.58

###### g_hash_table_unref

Atomically decrements the reference count of `hash_table` by one. If the reference count drops to 0, all keys and values will be destroyed, and all memory allocated by the hash table is released. This function is MT-safe and may be called from any thread.

since: 2.10