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().
46 To destroy a #GHashTable use g_hash_table_destroy().
49 <!-- ##### SECTION See_Also ##### -->
54 <!-- ##### SECTION Stability_Level ##### -->
57 <!-- ##### STRUCT GHashTable ##### -->
59 The <structname>GHashTable</structname> struct is an opaque data structure to represent a
60 <link linkend="glib-Hash-Tables">Hash Table</link>.
61 It should only be accessed via the following functions.
65 <!-- ##### FUNCTION g_hash_table_new ##### -->
75 <!-- ##### FUNCTION g_hash_table_new_full ##### -->
87 <!-- ##### USER_FUNCTION GHashFunc ##### -->
89 Specifies the type of the hash function which is passed to
90 g_hash_table_new() when a #GHashTable is created.
93 The function is passed a key and should return a #guint hash value.
94 The functions g_direct_hash(), g_int_hash() and g_str_hash() provide
95 hash functions which can be used when the key is a #gpointer, #gint, and
99 FIXME: Need more here.
100 The hash values should be evenly distributed over a fairly large range?
101 The modulus is taken with the hash table size (a prime number)
102 to find the 'bucket' to place each key into.
103 The function should also be very fast, since it is called for each key
108 @Returns: the hash value corresponding to the key.
111 <!-- ##### USER_FUNCTION GEqualFunc ##### -->
113 Specifies the type of a function used to test two values for
114 equality. The function should return %TRUE if both values are equal and
119 @b: a value to compare with.
120 @Returns: %TRUE if @a = @b; %FALSE otherwise.
123 <!-- ##### FUNCTION g_hash_table_insert ##### -->
133 <!-- ##### FUNCTION g_hash_table_replace ##### -->
143 <!-- ##### FUNCTION g_hash_table_size ##### -->
152 <!-- ##### FUNCTION g_hash_table_lookup ##### -->
162 <!-- ##### FUNCTION g_hash_table_lookup_extended ##### -->
174 <!-- ##### FUNCTION g_hash_table_foreach ##### -->
184 <!-- ##### FUNCTION g_hash_table_find ##### -->
195 <!-- ##### USER_FUNCTION GHFunc ##### -->
197 Specifies the type of the function passed to g_hash_table_foreach().
198 It is called with each key/value pair, together with the @user_data parameter
199 which is passed to g_hash_table_foreach().
203 @value: the value corresponding to the key.
204 @user_data: user data passed to g_hash_table_foreach().
207 <!-- ##### FUNCTION g_hash_table_remove ##### -->
217 <!-- ##### FUNCTION g_hash_table_steal ##### -->
227 <!-- ##### FUNCTION g_hash_table_foreach_remove ##### -->
238 <!-- ##### FUNCTION g_hash_table_foreach_steal ##### -->
249 <!-- ##### USER_FUNCTION GHRFunc ##### -->
251 Specifies the type of the function passed to g_hash_table_foreach_remove().
252 It is called with each key/value pair, together with the @user_data parameter
253 passed to g_hash_table_foreach_remove().
254 It should return %TRUE if the key/value pair should be removed from the
259 @value: the value associated with the key.
260 @user_data: user data passed to g_hash_table_remove().
261 @Returns: %TRUE if the key/value pair should be removed from the #GHashTable.
264 <!-- ##### MACRO g_hash_table_freeze ##### -->
266 This function is deprecated and will be removed in the next major
267 release of GLib. It does nothing.
270 @hash_table: a #GHashTable
273 <!-- ##### MACRO g_hash_table_thaw ##### -->
275 This function is deprecated and will be removed in the next major
276 release of GLib. It does nothing.
279 @hash_table: a #GHashTable
282 <!-- ##### FUNCTION g_hash_table_destroy ##### -->
290 <!-- ##### FUNCTION g_hash_table_ref ##### -->
299 <!-- ##### FUNCTION g_hash_table_unref ##### -->
307 <!-- ##### FUNCTION g_direct_equal ##### -->
317 <!-- ##### FUNCTION g_direct_hash ##### -->
326 <!-- ##### FUNCTION g_int_equal ##### -->
336 <!-- ##### FUNCTION g_int_hash ##### -->
345 <!-- ##### FUNCTION g_str_equal ##### -->
354 <!-- ##### FUNCTION g_str_hash ##### -->