1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 associations between keys and values so that given a key the value
8 <!-- ##### SECTION Long_Description ##### -->
10 A #GHashTable provides associations between keys and values which
11 is optimized so that given a key, the associated value can be found
15 Note that neither keys nor values are copied when inserted into the
16 #GHashTable, so they must exist for the lifetime of the #GHashTable.
17 This means that the use of static strings is OK, but temporary
18 strings (i.e. those created in buffers and those returned by GTK+ widgets)
19 should be copied with g_strdup() before being inserted.
22 If keys or values are dynamically allocated, you must be careful to ensure
23 that they are freed when they are removed from the #GHashTable, and also
24 when they are overwritten by new insertions into the #GHashTable.
25 It is also not advisable to mix static strings and dynamically-allocated
26 strings in a #GHashTable, because it then becomes difficult to determine
27 whether the string should be freed.
30 To create a #GHashTable, use g_hash_table_new().
33 To insert a key and value into a #GHashTable, use g_hash_table_insert().
36 To lookup a value corresponding to a given key, use g_hash_table_lookup()
37 and g_hash_table_lookup_extended().
40 To remove a key and value, use g_hash_table_remove().
43 To call a function for each key and value pair use g_hash_table_foreach()
44 or use a iterator to iterate over the key/value pairs in the hash table, see
48 To destroy a #GHashTable use g_hash_table_destroy().
51 <!-- ##### SECTION See_Also ##### -->
56 <!-- ##### SECTION Stability_Level ##### -->
59 <!-- ##### STRUCT GHashTable ##### -->
61 The <structname>GHashTable</structname> struct is an opaque data structure to represent a
62 <link linkend="glib-Hash-Tables">Hash Table</link>.
63 It should only be accessed via the following functions.
67 <!-- ##### FUNCTION g_hash_table_new ##### -->
77 <!-- ##### FUNCTION g_hash_table_new_full ##### -->
89 <!-- ##### USER_FUNCTION GHashFunc ##### -->
91 Specifies the type of the hash function which is passed to
92 g_hash_table_new() when a #GHashTable is created.
95 The function is passed a key and should return a #guint hash value.
96 The functions g_direct_hash(), g_int_hash() and g_str_hash() provide
97 hash functions which can be used when the key is a #gpointer, #gint, and
101 <!-- FIXME: Need more here. -->
102 The hash values should be evenly distributed over a fairly large range?
103 The modulus is taken with the hash table size (a prime number)
104 to find the 'bucket' to place each key into.
105 The function should also be very fast, since it is called for each key
110 @Returns: the hash value corresponding to the key.
113 <!-- ##### USER_FUNCTION GEqualFunc ##### -->
115 Specifies the type of a function used to test two values for
116 equality. The function should return %TRUE if both values are equal and
121 @b: a value to compare with.
122 @Returns: %TRUE if @a = @b; %FALSE otherwise.
125 <!-- ##### FUNCTION g_hash_table_insert ##### -->
135 <!-- ##### FUNCTION g_hash_table_replace ##### -->
145 <!-- ##### FUNCTION g_hash_table_size ##### -->
154 <!-- ##### FUNCTION g_hash_table_lookup ##### -->
164 <!-- ##### FUNCTION g_hash_table_lookup_extended ##### -->
176 <!-- ##### FUNCTION g_hash_table_foreach ##### -->
186 <!-- ##### FUNCTION g_hash_table_find ##### -->
197 <!-- ##### USER_FUNCTION GHFunc ##### -->
199 Specifies the type of the function passed to g_hash_table_foreach().
200 It is called with each key/value pair, together with the @user_data parameter
201 which is passed to g_hash_table_foreach().
205 @value: the value corresponding to the key.
206 @user_data: user data passed to g_hash_table_foreach().
209 <!-- ##### FUNCTION g_hash_table_remove ##### -->
219 <!-- ##### FUNCTION g_hash_table_steal ##### -->
229 <!-- ##### FUNCTION g_hash_table_foreach_remove ##### -->
240 <!-- ##### FUNCTION g_hash_table_foreach_steal ##### -->
251 <!-- ##### FUNCTION g_hash_table_remove_all ##### -->
259 <!-- ##### FUNCTION g_hash_table_steal_all ##### -->
267 <!-- ##### FUNCTION g_hash_table_get_keys ##### -->
276 <!-- ##### FUNCTION g_hash_table_get_values ##### -->
285 <!-- ##### USER_FUNCTION GHRFunc ##### -->
287 Specifies the type of the function passed to g_hash_table_foreach_remove().
288 It is called with each key/value pair, together with the @user_data parameter
289 passed to g_hash_table_foreach_remove().
290 It should return %TRUE if the key/value pair should be removed from the
295 @value: the value associated with the key.
296 @user_data: user data passed to g_hash_table_remove().
297 @Returns: %TRUE if the key/value pair should be removed from the #GHashTable.
300 <!-- ##### MACRO g_hash_table_freeze ##### -->
302 This function is deprecated and will be removed in the next major
303 release of GLib. It does nothing.
306 @hash_table: a #GHashTable
309 <!-- ##### MACRO g_hash_table_thaw ##### -->
311 This function is deprecated and will be removed in the next major
312 release of GLib. It does nothing.
315 @hash_table: a #GHashTable
318 <!-- ##### FUNCTION g_hash_table_destroy ##### -->
326 <!-- ##### FUNCTION g_hash_table_ref ##### -->
335 <!-- ##### FUNCTION g_hash_table_unref ##### -->
343 <!-- ##### STRUCT GHashTableIter ##### -->
345 A GHashTableIter structure represents an iterator that can be
346 used to iterate over the elements of a #GHashTable. GHashTableIter
347 structures are typically allocated on the stack and then initialized
348 with g_hash_table_iter_init().
352 <!-- ##### FUNCTION g_hash_table_iter_init ##### -->
361 <!-- ##### FUNCTION g_hash_table_iter_next ##### -->
372 <!-- ##### FUNCTION g_hash_table_iter_get_hash_table ##### -->
381 <!-- ##### FUNCTION g_hash_table_iter_remove ##### -->
389 <!-- ##### FUNCTION g_hash_table_iter_steal ##### -->
397 <!-- ##### FUNCTION g_direct_equal ##### -->
407 <!-- ##### FUNCTION g_direct_hash ##### -->
416 <!-- ##### FUNCTION g_int_equal ##### -->
426 <!-- ##### FUNCTION g_int_hash ##### -->
435 <!-- ##### FUNCTION g_int64_equal ##### -->
445 <!-- ##### FUNCTION g_int64_hash ##### -->
454 <!-- ##### FUNCTION g_double_equal ##### -->
464 <!-- ##### FUNCTION g_double_hash ##### -->
473 <!-- ##### FUNCTION g_str_equal ##### -->
482 <!-- ##### FUNCTION g_str_hash ##### -->