typedef typedefG_BEGIN_DECLS struct _GHashTable | GHashTable |
typedef gboolean(* | GHRFunc |
typedef struct _GHashTableIter | GHashTableIter |
IMPORT_C GHashTable * | g_hash_table_new | ( | GHashFunc | hash_func, |
GEqualFunc | key_equal_func | |||
) |
g_hash_table_new: : a function to create a hash value from a key. Hash values are used to determine where keys are stored within the GHashTable data structure. The g_direct_hash(), g_int_hash() and g_str_hash() functions are provided for some common types of keys. If hash_func is NULL, g_direct_hash() is used. : a function to check two keys for equality. This is used when looking up keys in the GHashTable. The g_direct_equal(), g_int_equal() and g_str_equal() functions are provided for the most common types of keys. If is NULL, keys are compared directly in a similar fashion to g_direct_equal(), but without the overhead of a function call.
Creates a new GHashTable with a reference count of 1.
Return value: a new GHashTable.
IMPORT_C GHashTable * | g_hash_table_new_full | ( | GHashFunc | hash_func, |
GEqualFunc | key_equal_func, | |||
GDestroyNotify | key_destroy_func, | |||
GDestroyNotify | value_destroy_func | |||
) |
g_hash_table_new_full: : a function to create a hash value from a key. : a function to check two keys for equality. : a function to free the memory allocated for the key used when removing the entry from the GHashTable or NULL if you don't want to supply such a function. : a function to free the memory allocated for the value used when removing the entry from the GHashTable or NULL if you don't want to supply such a function.
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.
Return value: a new GHashTable.
IMPORT_C void | g_hash_table_destroy | ( | GHashTable * | hash_table | ) |
g_hash_table_destroy: : a GHashTable.
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.
IMPORT_C void | g_hash_table_insert | ( | GHashTable * | hash_table, |
gpointer | key, | |||
gpointer | value | |||
) |
g_hash_table_insert: : a GHashTable. : a key to insert. : 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 when creating the GHashTable, the old value is freed using that function. If you supplied a when creating the GHashTable, the passed key is freed using that function.
IMPORT_C void | g_hash_table_replace | ( | GHashTable * | hash_table, |
gpointer | key, | |||
gpointer | value | |||
) |
g_hash_table_replace: : a GHashTable. : a key to insert. : 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 when creating the GHashTable, the old value is freed using that function. If you supplied a when creating the GHashTable, the old key is freed using that function.
IMPORT_C gboolean | g_hash_table_remove | ( | GHashTable * | hash_table, |
gconstpointer | key | |||
) |
g_hash_table_remove: : a GHashTable. : the key to remove.
Removes a key and its associated value from a GHashTable.
If the GHashTable was created using g_hash_table_new_full(), the key and value are freed using the supplied destroy functions, otherwise you have to make sure that any dynamically allocated values are freed yourself.
Return value: TRUE if the key was found and removed from the GHashTable.
IMPORT_C void | g_hash_table_remove_all | ( | GHashTable * | hash_table | ) |
g_hash_table_remove_all: : 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
IMPORT_C gboolean | g_hash_table_steal | ( | GHashTable * | hash_table, |
gconstpointer | key | |||
) |
g_hash_table_steal: : a GHashTable. : the key to remove.
Removes a key and its associated value from a GHashTable without calling the key and value destroy functions.
Return value: TRUE if the key was found and removed from the GHashTable.
IMPORT_C void | g_hash_table_steal_all | ( | GHashTable * | hash_table | ) |
g_hash_table_steal_all: : a GHashTable.
Removes all keys and their associated values from a GHashTable without calling the key and value destroy functions.
Since: 2.12
IMPORT_C gpointer | g_hash_table_lookup | ( | GHashTable * | hash_table, |
gconstpointer | key | |||
) |
g_hash_table_lookup: : a GHashTable. : the key to look up.
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().
Return value: the associated value, or NULL if the key is not found.
IMPORT_C gboolean | g_hash_table_lookup_extended | ( | GHashTable * | hash_table, |
gconstpointer | lookup_key, | |||
gpointer * | orig_key, | |||
gpointer * | value | |||
) |
g_hash_table_lookup_extended: : a GHashTable : the key to look up : return location for the original key, or NULL : return location for the value associated with the key, or NULL
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().
You can actually pass NULL for to test whether the NULL key exists.
Return value: TRUE if the key was found in the GHashTable.
IMPORT_C void | g_hash_table_foreach | ( | GHashTable * | hash_table, |
GHFunc | func, | |||
gpointer | user_data | |||
) |
g_hash_table_foreach: : a GHashTable. : the function to call for each key/value pair. : user data to pass to the function.
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 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().
See g_hash_table_find() for performance caveats for linear order searches in contrast to g_hash_table_lookup().
IMPORT_C gpointer | g_hash_table_find | ( | GHashTable * | hash_table, |
GHRFunc | predicate, | |||
gpointer | user_data | |||
) |
g_hash_table_find: : a GHashTable. : function to test the key/value pairs for a certain property. : user data to pass to the function.
Calls the given function for key/value pairs in the GHashTable until returns TRUE. The function is passed the key and value of each pair, and the given parameter. The hash table may not be modified while iterating over it (you can't add/remove items).
Note, that hash tables are really only optimized for forward lookups, i.e. g_hash_table_lookup(). So code that frequently issues g_hash_table_find() or g_hash_table_foreach() (e.g. in the order of once per every entry in a hash table) should probably be reworked to use additional or different data structures for reverse lookups (keep in mind that an O(n) find/foreach operation issued for all n values in a hash table ends up needing O(n*n) operations).
Return value: The value of the first key/value pair is returned, for which func evaluates to TRUE. If no pair with the requested property is found, NULL is returned.
Since: 2.4
IMPORT_C guint | g_hash_table_foreach_remove | ( | GHashTable * | hash_table, |
GHRFunc | func, | |||
gpointer | user_data | |||
) |
g_hash_table_foreach_remove: : a GHashTable. : the function to call for each key/value pair. : user data to pass to the function.
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.
See GHashTableIter for an alternative way to loop over the key/value pairs in the hash table.
Return value: the number of key/value pairs removed.
IMPORT_C guint | g_hash_table_foreach_steal | ( | GHashTable * | hash_table, |
GHRFunc | func, | |||
gpointer | user_data | |||
) |
g_hash_table_foreach_steal: : a GHashTable. : the function to call for each key/value pair. : user data to pass to the function.
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.
See GHashTableIter for an alternative way to loop over the key/value pairs in the hash table.
Return value: the number of key/value pairs removed.
IMPORT_C guint | g_hash_table_size | ( | GHashTable * | hash_table | ) |
g_hash_table_size: : a GHashTable.
Returns the number of elements contained in the GHashTable.
Return value: the number of key/value pairs in the GHashTable.
IMPORT_C GList * | g_hash_table_get_keys | ( | GHashTable * | hash_table | ) |
g_hash_table_get_keys: : a GHashTable
Retrieves every key inside . The returned data is valid until is modified.
Return value: a GList containing all the keys inside the hash table. The content of the list is owned by the hash table and should not be modified or freed. Use g_list_free() when done using the list.
Since: 2.14
IMPORT_C GList * | g_hash_table_get_values | ( | GHashTable * | hash_table | ) |
g_hash_table_get_values: : a GHashTable
Retrieves every value inside . The returned data is valid until is modified.
Return value: a GList containing all the values inside the hash table. The content of the list is owned by the hash table and should not be modified or freed. Use g_list_free() when done using the list.
Since: 2.14
IMPORT_C void | g_hash_table_iter_init | ( | GHashTableIter * | iter, |
GHashTable * | hash_table | |||
) |
g_hash_table_iter_init: : an uninitialized GHashTableIter. : a GHashTable.
Initializes a key/value pair iterator and associates it with . Modifying the hash table after calling this function invalidates the returned iterator. |[ GHashTableIter iter; gpointer key, value;
g_hash_table_iter_init (&iter, hash_table); while (g_hash_table_iter_next (&iter, &key, &value)) { / do something with key and value / } ]|
Since: 2.16
IMPORT_C gboolean | g_hash_table_iter_next | ( | GHashTableIter * | iter, |
gpointer * | key, | |||
gpointer * | value | |||
) |
g_hash_table_iter_next: : an initialized GHashTableIter. : a location to store the key, or NULL. : a location to store the value, or NULL.
Advances and retrieves the key and/or value that are now pointed to as a result of this advancement. If FALSE is returned, and are not set, and the iterator becomes invalid.
Return value: FALSE if the end of the GHashTable has been reached.
Since: 2.16
IMPORT_C GHashTable * | g_hash_table_iter_get_hash_table | ( | GHashTableIter * | iter | ) |
g_hash_table_iter_get_hash_table: : an initialized GHashTableIter.
Returns the GHashTable associated with .
Return value: the GHashTable associated with .
Since: 2.16
IMPORT_C void | g_hash_table_iter_remove | ( | GHashTableIter * | iter | ) |
g_hash_table_iter_remove(): : an initialized GHashTableIter.
Removes the key/value pair currently pointed to by the iterator from its associated GHashTable. Can only be called after g_hash_table_iter_next() returned TRUE, and cannot be called more than once for the same key/value pair.
If the GHashTable was created using g_hash_table_new_full(), the key and value are freed using the supplied destroy functions, otherwise you have to make sure that any dynamically allocated values are freed yourself.
Since: 2.16
IMPORT_C void | g_hash_table_iter_steal | ( | GHashTableIter * | iter | ) |
g_hash_table_iter_steal(): : an initialized GHashTableIter.
Removes the key/value pair currently pointed to by the iterator from its associated GHashTable, without calling the key and value destroy functions. Can only be called after g_hash_table_iter_next() returned TRUE, and cannot be called more than once for the same key/value pair.
Since: 2.16
IMPORT_C GHashTable * | g_hash_table_ref | ( | GHashTable * | hash_table | ) |
g_hash_table_ref: : a valid GHashTable.
Atomically increments the reference count of by one. This function is MT-safe and may be called from any thread.
Return value: the passed in GHashTable.
Since: 2.10
IMPORT_C void | g_hash_table_unref | ( | GHashTable * | hash_table | ) |
g_hash_table_unref: : a valid GHashTable.
Atomically decrements the reference count of 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
IMPORT_C gboolean | g_str_equal | ( | gconstpointer | v1, |
gconstpointer | v2 | |||
) |
g_str_equal: : a key : a key to compare with
Compares two strings for byte-by-byte equality and returns TRUE if they are equal. It can be passed to g_hash_table_new() as the parameter, when using strings as keys in a GHashTable.
Returns: TRUE if the two keys match
IMPORT_C guint | g_str_hash | ( | gconstpointer | v | ) |
g_str_hash: : a string key
Converts a string to a hash value. It can be passed to g_hash_table_new() as the parameter, when using strings as keys in a GHashTable.
Returns: a hash value corresponding to the key
IMPORT_C gboolean | g_int_equal | ( | gconstpointer | v1, |
gconstpointer | v2 | |||
) |
g_int_equal: : a pointer to a gint key. : a pointer to a gint key to compare with .
Compares the two gint values being pointed to and returns TRUE if they are equal. It can be passed to g_hash_table_new() as the parameter, when using pointers to integers as keys in a GHashTable.
Returns: TRUE if the two keys match.
IMPORT_C guint | g_int_hash | ( | gconstpointer | v | ) |
g_int_hash: : a pointer to a gint key
Converts a pointer to a gint to a hash value. It can be passed to g_hash_table_new() as the parameter, when using pointers to integers values as keys in a GHashTable.
Returns: a hash value corresponding to the key.
IMPORT_C guint | g_direct_hash | ( | gconstpointer | v | ) |
g_direct_hash: : a gpointer key
Converts a gpointer to a hash value. It can be passed to g_hash_table_new() as the parameter, when using pointers as keys in a GHashTable.
Returns: a hash value corresponding to the key.
IMPORT_C gboolean | g_direct_equal | ( | gconstpointer | v1, |
gconstpointer | v2 | |||
) |
g_direct_equal: : a key. : a key to compare with .
Compares two gpointer arguments and returns TRUE if they are equal. It can be passed to g_hash_table_new() as the parameter, when using pointers as keys in a GHashTable.
Returns: TRUE if the two keys match.