ghash.h File Reference

__G_HASH_H__

Typedef GHashTable

typedef typedefG_BEGIN_DECLS struct _GHashTableGHashTable

Typedef GHRFunc

typedef gboolean(*GHRFunc

Typedef GHashTableIter

typedef struct _GHashTableIterGHashTableIter

g_hash_table_new ( GHashFunc, GEqualFunc )

IMPORT_C GHashTable *g_hash_table_new(GHashFunchash_func,
GEqualFunckey_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.

g_hash_table_new_full ( GHashFunc, GEqualFunc, GDestroyNotify, GDestroyNotify )

IMPORT_C GHashTable *g_hash_table_new_full(GHashFunchash_func,
GEqualFunckey_equal_func,
GDestroyNotifykey_destroy_func,
GDestroyNotifyvalue_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.

g_hash_table_destroy ( GHashTable * )

IMPORT_C voidg_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.

g_hash_table_insert ( GHashTable *, gpointer, gpointer )

IMPORT_C voidg_hash_table_insert(GHashTable *hash_table,
gpointerkey,
gpointervalue
)

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.

g_hash_table_replace ( GHashTable *, gpointer, gpointer )

IMPORT_C voidg_hash_table_replace(GHashTable *hash_table,
gpointerkey,
gpointervalue
)

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.

g_hash_table_remove ( GHashTable *, gconstpointer )

IMPORT_C gbooleang_hash_table_remove(GHashTable *hash_table,
gconstpointerkey
)

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.

g_hash_table_remove_all ( GHashTable * )

IMPORT_C voidg_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

g_hash_table_steal ( GHashTable *, gconstpointer )

IMPORT_C gbooleang_hash_table_steal(GHashTable *hash_table,
gconstpointerkey
)

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.

g_hash_table_steal_all ( GHashTable * )

IMPORT_C voidg_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

g_hash_table_lookup ( GHashTable *, gconstpointer )

IMPORT_C gpointerg_hash_table_lookup(GHashTable *hash_table,
gconstpointerkey
)

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.

g_hash_table_lookup_extended ( GHashTable *, gconstpointer, gpointer *, gpointer * )

IMPORT_C gbooleang_hash_table_lookup_extended(GHashTable *hash_table,
gconstpointerlookup_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.

g_hash_table_foreach ( GHashTable *, GHFunc, gpointer )

IMPORT_C voidg_hash_table_foreach(GHashTable *hash_table,
GHFuncfunc,
gpointeruser_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().

g_hash_table_find ( GHashTable *, GHRFunc, gpointer )

IMPORT_C gpointerg_hash_table_find(GHashTable *hash_table,
GHRFuncpredicate,
gpointeruser_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

g_hash_table_foreach_remove ( GHashTable *, GHRFunc, gpointer )

IMPORT_C guintg_hash_table_foreach_remove(GHashTable *hash_table,
GHRFuncfunc,
gpointeruser_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.

g_hash_table_foreach_steal ( GHashTable *, GHRFunc, gpointer )

IMPORT_C guintg_hash_table_foreach_steal(GHashTable *hash_table,
GHRFuncfunc,
gpointeruser_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.

g_hash_table_size ( GHashTable * )

IMPORT_C guintg_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.

g_hash_table_get_keys ( 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

g_hash_table_get_values ( GHashTable * )

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

g_hash_table_iter_init ( GHashTableIter *, GHashTable * )

IMPORT_C voidg_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

g_hash_table_iter_next ( GHashTableIter *, gpointer *, gpointer * )

IMPORT_C gbooleang_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

g_hash_table_iter_get_hash_table ( GHashTableIter * )

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

g_hash_table_iter_remove ( GHashTableIter * )

IMPORT_C voidg_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

g_hash_table_iter_steal ( GHashTableIter * )

IMPORT_C voidg_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

g_hash_table_ref ( GHashTable * )

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

g_hash_table_unref ( GHashTable * )

IMPORT_C voidg_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

g_hash_table_freeze

g_hash_table_thaw

g_str_equal ( gconstpointer, gconstpointer )

IMPORT_C gbooleang_str_equal(gconstpointerv1,
gconstpointerv2
)

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

g_str_hash ( gconstpointer )

IMPORT_C guintg_str_hash(gconstpointerv)

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

g_int_equal ( gconstpointer, gconstpointer )

IMPORT_C gbooleang_int_equal(gconstpointerv1,
gconstpointerv2
)

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.

g_int_hash ( gconstpointer )

IMPORT_C guintg_int_hash(gconstpointerv)

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.

g_direct_hash ( gconstpointer )

IMPORT_C guintg_direct_hash(gconstpointerv)

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.

g_direct_equal ( gconstpointer, gconstpointer )

IMPORT_C gbooleang_direct_equal(gconstpointerv1,
gconstpointerv2
)

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.