1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.HashTable;
26 
27 private import glib.ConstructionException;
28 private import glib.ListG;
29 private import glib.c.functions;
30 public  import glib.c.types;
31 public  import gtkc.glibtypes;
32 
33 
34 /**
35  * The #GHashTable struct is an opaque data structure to represent a
36  * [Hash Table][glib-Hash-Tables]. It should only be accessed via the
37  * following functions.
38  */
39 public class HashTable
40 {
41 	/** the main Gtk struct */
42 	protected GHashTable* gHashTable;
43 	protected bool ownedRef;
44 
45 	/** Get the main Gtk struct */
46 	public GHashTable* getHashTableStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gHashTable;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)gHashTable;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GHashTable* gHashTable, bool ownedRef = false)
63 	{
64 		this.gHashTable = gHashTable;
65 		this.ownedRef = ownedRef;
66 	}
67 
68 
69 	/**
70 	 * This is a convenience function for using a #GHashTable as a set.  It
71 	 * is equivalent to calling g_hash_table_replace() with @key as both the
72 	 * key and the value.
73 	 *
74 	 * When a hash table only ever contains keys that have themselves as the
75 	 * corresponding value it is able to be stored more efficiently.  See
76 	 * the discussion in the section description.
77 	 *
78 	 * Starting from GLib 2.40, this function returns a boolean value to
79 	 * indicate whether the newly added value was already in the hash table
80 	 * or not.
81 	 *
82 	 * Params:
83 	 *     key = a key to insert
84 	 *
85 	 * Returns: %TRUE if the key did not exist yet
86 	 *
87 	 * Since: 2.32
88 	 */
89 	public bool add(void* key)
90 	{
91 		return g_hash_table_add(gHashTable, key) != 0;
92 	}
93 
94 	/**
95 	 * Checks if @key is in @hash_table.
96 	 *
97 	 * Params:
98 	 *     key = a key to check
99 	 *
100 	 * Returns: %TRUE if @key is in @hash_table, %FALSE otherwise.
101 	 *
102 	 * Since: 2.32
103 	 */
104 	public bool contains(void* key)
105 	{
106 		return g_hash_table_contains(gHashTable, key) != 0;
107 	}
108 
109 	/**
110 	 * Destroys all keys and values in the #GHashTable and decrements its
111 	 * reference count by 1. If keys and/or values are dynamically allocated,
112 	 * you should either free them first or create the #GHashTable with destroy
113 	 * notifiers using g_hash_table_new_full(). In the latter case the destroy
114 	 * functions you supplied will be called on all keys and values during the
115 	 * destruction phase.
116 	 */
117 	public void destroy()
118 	{
119 		g_hash_table_destroy(gHashTable);
120 	}
121 
122 	/**
123 	 * Calls the given function for key/value pairs in the #GHashTable
124 	 * until @predicate returns %TRUE. The function is passed the key
125 	 * and value of each pair, and the given @user_data parameter. The
126 	 * hash table may not be modified while iterating over it (you can't
127 	 * add/remove items).
128 	 *
129 	 * Note, that hash tables are really only optimized for forward
130 	 * lookups, i.e. g_hash_table_lookup(). So code that frequently issues
131 	 * g_hash_table_find() or g_hash_table_foreach() (e.g. in the order of
132 	 * once per every entry in a hash table) should probably be reworked
133 	 * to use additional or different data structures for reverse lookups
134 	 * (keep in mind that an O(n) find/foreach operation issued for all n
135 	 * values in a hash table ends up needing O(n*n) operations).
136 	 *
137 	 * Params:
138 	 *     predicate = function to test the key/value pairs for a certain property
139 	 *     userData = user data to pass to the function
140 	 *
141 	 * Returns: The value of the first key/value pair is returned,
142 	 *     for which @predicate evaluates to %TRUE. If no pair with the
143 	 *     requested property is found, %NULL is returned.
144 	 *
145 	 * Since: 2.4
146 	 */
147 	public void* find(GHRFunc predicate, void* userData)
148 	{
149 		return g_hash_table_find(gHashTable, predicate, userData);
150 	}
151 
152 	/**
153 	 * Calls the given function for each of the key/value pairs in the
154 	 * #GHashTable.  The function is passed the key and value of each
155 	 * pair, and the given @user_data parameter.  The hash table may not
156 	 * be modified while iterating over it (you can't add/remove
157 	 * items). To remove all items matching a predicate, use
158 	 * g_hash_table_foreach_remove().
159 	 *
160 	 * See g_hash_table_find() for performance caveats for linear
161 	 * order searches in contrast to g_hash_table_lookup().
162 	 *
163 	 * Params:
164 	 *     func = the function to call for each key/value pair
165 	 *     userData = user data to pass to the function
166 	 */
167 	public void foreac(GHFunc func, void* userData)
168 	{
169 		g_hash_table_foreach(gHashTable, func, userData);
170 	}
171 
172 	/**
173 	 * Calls the given function for each key/value pair in the
174 	 * #GHashTable. If the function returns %TRUE, then the key/value
175 	 * pair is removed from the #GHashTable. If you supplied key or
176 	 * value destroy functions when creating the #GHashTable, they are
177 	 * used to free the memory allocated for the removed keys and values.
178 	 *
179 	 * See #GHashTableIter for an alternative way to loop over the
180 	 * key/value pairs in the hash table.
181 	 *
182 	 * Params:
183 	 *     func = the function to call for each key/value pair
184 	 *     userData = user data to pass to the function
185 	 *
186 	 * Returns: the number of key/value pairs removed
187 	 */
188 	public uint foreachRemove(GHRFunc func, void* userData)
189 	{
190 		return g_hash_table_foreach_remove(gHashTable, func, userData);
191 	}
192 
193 	/**
194 	 * Calls the given function for each key/value pair in the
195 	 * #GHashTable. If the function returns %TRUE, then the key/value
196 	 * pair is removed from the #GHashTable, but no key or value
197 	 * destroy functions are called.
198 	 *
199 	 * See #GHashTableIter for an alternative way to loop over the
200 	 * key/value pairs in the hash table.
201 	 *
202 	 * Params:
203 	 *     func = the function to call for each key/value pair
204 	 *     userData = user data to pass to the function
205 	 *
206 	 * Returns: the number of key/value pairs removed.
207 	 */
208 	public uint foreachSteal(GHRFunc func, void* userData)
209 	{
210 		return g_hash_table_foreach_steal(gHashTable, func, userData);
211 	}
212 
213 	/**
214 	 * Retrieves every key inside @hash_table. The returned data is valid
215 	 * until changes to the hash release those keys.
216 	 *
217 	 * This iterates over every entry in the hash table to build its return value.
218 	 * To iterate over the entries in a #GHashTable more efficiently, use a
219 	 * #GHashTableIter.
220 	 *
221 	 * Returns: a #GList containing all the keys
222 	 *     inside the hash table. The content of the list is owned by the
223 	 *     hash table and should not be modified or freed. Use g_list_free()
224 	 *     when done using the list.
225 	 *
226 	 * Since: 2.14
227 	 */
228 	public ListG getKeys()
229 	{
230 		auto p = g_hash_table_get_keys(gHashTable);
231 
232 		if(p is null)
233 		{
234 			return null;
235 		}
236 
237 		return new ListG(cast(GList*) p);
238 	}
239 
240 	/**
241 	 * Retrieves every key inside @hash_table, as an array.
242 	 *
243 	 * The returned array is %NULL-terminated but may contain %NULL as a
244 	 * key.  Use @length to determine the true length if it's possible that
245 	 * %NULL was used as the value for a key.
246 	 *
247 	 * Note: in the common case of a string-keyed #GHashTable, the return
248 	 * value of this function can be conveniently cast to (const gchar **).
249 	 *
250 	 * This iterates over every entry in the hash table to build its return value.
251 	 * To iterate over the entries in a #GHashTable more efficiently, use a
252 	 * #GHashTableIter.
253 	 *
254 	 * You should always free the return result with g_free().  In the
255 	 * above-mentioned case of a string-keyed hash table, it may be
256 	 * appropriate to use g_strfreev() if you call g_hash_table_steal_all()
257 	 * first to transfer ownership of the keys.
258 	 *
259 	 * Returns: a
260 	 *     %NULL-terminated array containing each key from the table.
261 	 *
262 	 * Since: 2.40
263 	 */
264 	public void*[] getKeysAsArray()
265 	{
266 		uint length;
267 
268 		auto p = g_hash_table_get_keys_as_array(gHashTable, &length);
269 
270 		return p[0 .. length];
271 	}
272 
273 	/**
274 	 * Retrieves every value inside @hash_table. The returned data
275 	 * is valid until @hash_table is modified.
276 	 *
277 	 * This iterates over every entry in the hash table to build its return value.
278 	 * To iterate over the entries in a #GHashTable more efficiently, use a
279 	 * #GHashTableIter.
280 	 *
281 	 * Returns: a #GList containing all the values
282 	 *     inside the hash table. The content of the list is owned by the
283 	 *     hash table and should not be modified or freed. Use g_list_free()
284 	 *     when done using the list.
285 	 *
286 	 * Since: 2.14
287 	 */
288 	public ListG getValues()
289 	{
290 		auto p = g_hash_table_get_values(gHashTable);
291 
292 		if(p is null)
293 		{
294 			return null;
295 		}
296 
297 		return new ListG(cast(GList*) p);
298 	}
299 
300 	/**
301 	 * Inserts a new key and value into a #GHashTable.
302 	 *
303 	 * If the key already exists in the #GHashTable its current
304 	 * value is replaced with the new value. If you supplied a
305 	 * @value_destroy_func when creating the #GHashTable, the old
306 	 * value is freed using that function. If you supplied a
307 	 * @key_destroy_func when creating the #GHashTable, the passed
308 	 * key is freed using that function.
309 	 *
310 	 * Starting from GLib 2.40, this function returns a boolean value to
311 	 * indicate whether the newly added value was already in the hash table
312 	 * or not.
313 	 *
314 	 * Params:
315 	 *     key = a key to insert
316 	 *     value = the value to associate with the key
317 	 *
318 	 * Returns: %TRUE if the key did not exist yet
319 	 */
320 	public bool insert(void* key, void* value)
321 	{
322 		return g_hash_table_insert(gHashTable, key, value) != 0;
323 	}
324 
325 	/**
326 	 * Looks up a key in a #GHashTable. Note that this function cannot
327 	 * distinguish between a key that is not present and one which is present
328 	 * and has the value %NULL. If you need this distinction, use
329 	 * g_hash_table_lookup_extended().
330 	 *
331 	 * Params:
332 	 *     key = the key to look up
333 	 *
334 	 * Returns: the associated value, or %NULL if the key is not found
335 	 */
336 	public void* lookup(void* key)
337 	{
338 		return g_hash_table_lookup(gHashTable, key);
339 	}
340 
341 	/**
342 	 * Looks up a key in the #GHashTable, returning the original key and the
343 	 * associated value and a #gboolean which is %TRUE if the key was found. This
344 	 * is useful if you need to free the memory allocated for the original key,
345 	 * for example before calling g_hash_table_remove().
346 	 *
347 	 * You can actually pass %NULL for @lookup_key to test
348 	 * whether the %NULL key exists, provided the hash and equal functions
349 	 * of @hash_table are %NULL-safe.
350 	 *
351 	 * Params:
352 	 *     lookupKey = the key to look up
353 	 *     origKey = return location for the original key
354 	 *     value = return location for the value associated
355 	 *         with the key
356 	 *
357 	 * Returns: %TRUE if the key was found in the #GHashTable
358 	 */
359 	public bool lookupExtended(void* lookupKey, out void* origKey, out void* value)
360 	{
361 		return g_hash_table_lookup_extended(gHashTable, lookupKey, &origKey, &value) != 0;
362 	}
363 
364 	/**
365 	 * Creates a new #GHashTable with a reference count of 1.
366 	 *
367 	 * Hash values returned by @hash_func are used to determine where keys
368 	 * are stored within the #GHashTable data structure. The g_direct_hash(),
369 	 * g_int_hash(), g_int64_hash(), g_double_hash() and g_str_hash()
370 	 * functions are provided for some common types of keys.
371 	 * If @hash_func is %NULL, g_direct_hash() is used.
372 	 *
373 	 * @key_equal_func is used when looking up keys in the #GHashTable.
374 	 * The g_direct_equal(), g_int_equal(), g_int64_equal(), g_double_equal()
375 	 * and g_str_equal() functions are provided for the most common types
376 	 * of keys. If @key_equal_func is %NULL, keys are compared directly in
377 	 * a similar fashion to g_direct_equal(), but without the overhead of
378 	 * a function call. @key_equal_func is called with the key from the hash table
379 	 * as its first parameter, and the user-provided key to check against as
380 	 * its second.
381 	 *
382 	 * Params:
383 	 *     hashFunc = a function to create a hash value from a key
384 	 *     keyEqualFunc = a function to check two keys for equality
385 	 *
386 	 * Returns: a new #GHashTable
387 	 *
388 	 * Throws: ConstructionException GTK+ fails to create the object.
389 	 */
390 	public this(GHashFunc hashFunc, GEqualFunc keyEqualFunc)
391 	{
392 		auto p = g_hash_table_new(hashFunc, keyEqualFunc);
393 
394 		if(p is null)
395 		{
396 			throw new ConstructionException("null returned by new");
397 		}
398 
399 		this(cast(GHashTable*) p);
400 	}
401 
402 	/**
403 	 * Creates a new #GHashTable like g_hash_table_new() with a reference
404 	 * count of 1 and allows to specify functions to free the memory
405 	 * allocated for the key and value that get called when removing the
406 	 * entry from the #GHashTable.
407 	 *
408 	 * Since version 2.42 it is permissible for destroy notify functions to
409 	 * recursively remove further items from the hash table. This is only
410 	 * permissible if the application still holds a reference to the hash table.
411 	 * This means that you may need to ensure that the hash table is empty by
412 	 * calling g_hash_table_remove_all() before releasing the last reference using
413 	 * g_hash_table_unref().
414 	 *
415 	 * Params:
416 	 *     hashFunc = a function to create a hash value from a key
417 	 *     keyEqualFunc = a function to check two keys for equality
418 	 *     keyDestroyFunc = a function to free the memory allocated for the key
419 	 *         used when removing the entry from the #GHashTable, or %NULL
420 	 *         if you don't want to supply such a function.
421 	 *     valueDestroyFunc = a function to free the memory allocated for the
422 	 *         value used when removing the entry from the #GHashTable, or %NULL
423 	 *         if you don't want to supply such a function.
424 	 *
425 	 * Returns: a new #GHashTable
426 	 *
427 	 * Throws: ConstructionException GTK+ fails to create the object.
428 	 */
429 	public this(GHashFunc hashFunc, GEqualFunc keyEqualFunc, GDestroyNotify keyDestroyFunc, GDestroyNotify valueDestroyFunc)
430 	{
431 		auto p = g_hash_table_new_full(hashFunc, keyEqualFunc, keyDestroyFunc, valueDestroyFunc);
432 
433 		if(p is null)
434 		{
435 			throw new ConstructionException("null returned by new_full");
436 		}
437 
438 		this(cast(GHashTable*) p);
439 	}
440 
441 	/**
442 	 * Atomically increments the reference count of @hash_table by one.
443 	 * This function is MT-safe and may be called from any thread.
444 	 *
445 	 * Returns: the passed in #GHashTable
446 	 *
447 	 * Since: 2.10
448 	 */
449 	public HashTable doref()
450 	{
451 		auto p = g_hash_table_ref(gHashTable);
452 
453 		if(p is null)
454 		{
455 			return null;
456 		}
457 
458 		return new HashTable(cast(GHashTable*) p);
459 	}
460 
461 	/**
462 	 * Removes a key and its associated value from a #GHashTable.
463 	 *
464 	 * If the #GHashTable was created using g_hash_table_new_full(), the
465 	 * key and value are freed using the supplied destroy functions, otherwise
466 	 * you have to make sure that any dynamically allocated values are freed
467 	 * yourself.
468 	 *
469 	 * Params:
470 	 *     key = the key to remove
471 	 *
472 	 * Returns: %TRUE if the key was found and removed from the #GHashTable
473 	 */
474 	public bool remove(void* key)
475 	{
476 		return g_hash_table_remove(gHashTable, key) != 0;
477 	}
478 
479 	/**
480 	 * Removes all keys and their associated values from a #GHashTable.
481 	 *
482 	 * If the #GHashTable was created using g_hash_table_new_full(),
483 	 * the keys and values are freed using the supplied destroy functions,
484 	 * otherwise you have to make sure that any dynamically allocated
485 	 * values are freed yourself.
486 	 *
487 	 * Since: 2.12
488 	 */
489 	public void removeAll()
490 	{
491 		g_hash_table_remove_all(gHashTable);
492 	}
493 
494 	/**
495 	 * Inserts a new key and value into a #GHashTable similar to
496 	 * g_hash_table_insert(). The difference is that if the key
497 	 * already exists in the #GHashTable, it gets replaced by the
498 	 * new key. If you supplied a @value_destroy_func when creating
499 	 * the #GHashTable, the old value is freed using that function.
500 	 * If you supplied a @key_destroy_func when creating the
501 	 * #GHashTable, the old key is freed using that function.
502 	 *
503 	 * Starting from GLib 2.40, this function returns a boolean value to
504 	 * indicate whether the newly added value was already in the hash table
505 	 * or not.
506 	 *
507 	 * Params:
508 	 *     key = a key to insert
509 	 *     value = the value to associate with the key
510 	 *
511 	 * Returns: %TRUE if the key did not exist yet
512 	 */
513 	public bool replace(void* key, void* value)
514 	{
515 		return g_hash_table_replace(gHashTable, key, value) != 0;
516 	}
517 
518 	/**
519 	 * Returns the number of elements contained in the #GHashTable.
520 	 *
521 	 * Returns: the number of key/value pairs in the #GHashTable.
522 	 */
523 	public uint size()
524 	{
525 		return g_hash_table_size(gHashTable);
526 	}
527 
528 	/**
529 	 * Removes a key and its associated value from a #GHashTable without
530 	 * calling the key and value destroy functions.
531 	 *
532 	 * Params:
533 	 *     key = the key to remove
534 	 *
535 	 * Returns: %TRUE if the key was found and removed from the #GHashTable
536 	 */
537 	public bool steal(void* key)
538 	{
539 		return g_hash_table_steal(gHashTable, key) != 0;
540 	}
541 
542 	/**
543 	 * Removes all keys and their associated values from a #GHashTable
544 	 * without calling the key and value destroy functions.
545 	 *
546 	 * Since: 2.12
547 	 */
548 	public void stealAll()
549 	{
550 		g_hash_table_steal_all(gHashTable);
551 	}
552 
553 	/**
554 	 * Atomically decrements the reference count of @hash_table by one.
555 	 * If the reference count drops to 0, all keys and values will be
556 	 * destroyed, and all memory allocated by the hash table is released.
557 	 * This function is MT-safe and may be called from any thread.
558 	 *
559 	 * Since: 2.10
560 	 */
561 	public void unref()
562 	{
563 		g_hash_table_unref(gHashTable);
564 	}
565 
566 	/**
567 	 * Compares two #gpointer arguments and returns %TRUE if they are equal.
568 	 * It can be passed to g_hash_table_new() as the @key_equal_func
569 	 * parameter, when using opaque pointers compared by pointer value as
570 	 * keys in a #GHashTable.
571 	 *
572 	 * This equality function is also appropriate for keys that are integers
573 	 * stored in pointers, such as `GINT_TO_POINTER (n)`.
574 	 *
575 	 * Params:
576 	 *     v1 = a key
577 	 *     v2 = a key to compare with @v1
578 	 *
579 	 * Returns: %TRUE if the two keys match.
580 	 */
581 	public static bool directEqual(void* v1, void* v2)
582 	{
583 		return g_direct_equal(v1, v2) != 0;
584 	}
585 
586 	/**
587 	 * Converts a gpointer to a hash value.
588 	 * It can be passed to g_hash_table_new() as the @hash_func parameter,
589 	 * when using opaque pointers compared by pointer value as keys in a
590 	 * #GHashTable.
591 	 *
592 	 * This hash function is also appropriate for keys that are integers
593 	 * stored in pointers, such as `GINT_TO_POINTER (n)`.
594 	 *
595 	 * Params:
596 	 *     v = a #gpointer key
597 	 *
598 	 * Returns: a hash value corresponding to the key.
599 	 */
600 	public static uint directHash(void* v)
601 	{
602 		return g_direct_hash(v);
603 	}
604 
605 	/**
606 	 * Compares the two #gdouble values being pointed to and returns
607 	 * %TRUE if they are equal.
608 	 * It can be passed to g_hash_table_new() as the @key_equal_func
609 	 * parameter, when using non-%NULL pointers to doubles as keys in a
610 	 * #GHashTable.
611 	 *
612 	 * Params:
613 	 *     v1 = a pointer to a #gdouble key
614 	 *     v2 = a pointer to a #gdouble key to compare with @v1
615 	 *
616 	 * Returns: %TRUE if the two keys match.
617 	 *
618 	 * Since: 2.22
619 	 */
620 	public static bool doubleEqual(void* v1, void* v2)
621 	{
622 		return g_double_equal(v1, v2) != 0;
623 	}
624 
625 	/**
626 	 * Converts a pointer to a #gdouble to a hash value.
627 	 * It can be passed to g_hash_table_new() as the @hash_func parameter,
628 	 * It can be passed to g_hash_table_new() as the @hash_func parameter,
629 	 * when using non-%NULL pointers to doubles as keys in a #GHashTable.
630 	 *
631 	 * Params:
632 	 *     v = a pointer to a #gdouble key
633 	 *
634 	 * Returns: a hash value corresponding to the key.
635 	 *
636 	 * Since: 2.22
637 	 */
638 	public static uint doubleHash(void* v)
639 	{
640 		return g_double_hash(v);
641 	}
642 
643 	/**
644 	 * Compares the two #gint64 values being pointed to and returns
645 	 * %TRUE if they are equal.
646 	 * It can be passed to g_hash_table_new() as the @key_equal_func
647 	 * parameter, when using non-%NULL pointers to 64-bit integers as keys in a
648 	 * #GHashTable.
649 	 *
650 	 * Params:
651 	 *     v1 = a pointer to a #gint64 key
652 	 *     v2 = a pointer to a #gint64 key to compare with @v1
653 	 *
654 	 * Returns: %TRUE if the two keys match.
655 	 *
656 	 * Since: 2.22
657 	 */
658 	public static bool int64Equal(void* v1, void* v2)
659 	{
660 		return g_int64_equal(v1, v2) != 0;
661 	}
662 
663 	/**
664 	 * Converts a pointer to a #gint64 to a hash value.
665 	 *
666 	 * It can be passed to g_hash_table_new() as the @hash_func parameter,
667 	 * when using non-%NULL pointers to 64-bit integer values as keys in a
668 	 * #GHashTable.
669 	 *
670 	 * Params:
671 	 *     v = a pointer to a #gint64 key
672 	 *
673 	 * Returns: a hash value corresponding to the key.
674 	 *
675 	 * Since: 2.22
676 	 */
677 	public static uint int64Hash(void* v)
678 	{
679 		return g_int64_hash(v);
680 	}
681 
682 	/**
683 	 * Compares the two #gint values being pointed to and returns
684 	 * %TRUE if they are equal.
685 	 * It can be passed to g_hash_table_new() as the @key_equal_func
686 	 * parameter, when using non-%NULL pointers to integers as keys in a
687 	 * #GHashTable.
688 	 *
689 	 * Note that this function acts on pointers to #gint, not on #gint
690 	 * directly: if your hash table's keys are of the form
691 	 * `GINT_TO_POINTER (n)`, use g_direct_equal() instead.
692 	 *
693 	 * Params:
694 	 *     v1 = a pointer to a #gint key
695 	 *     v2 = a pointer to a #gint key to compare with @v1
696 	 *
697 	 * Returns: %TRUE if the two keys match.
698 	 */
699 	public static bool intEqual(void* v1, void* v2)
700 	{
701 		return g_int_equal(v1, v2) != 0;
702 	}
703 
704 	/**
705 	 * Converts a pointer to a #gint to a hash value.
706 	 * It can be passed to g_hash_table_new() as the @hash_func parameter,
707 	 * when using non-%NULL pointers to integer values as keys in a #GHashTable.
708 	 *
709 	 * Note that this function acts on pointers to #gint, not on #gint
710 	 * directly: if your hash table's keys are of the form
711 	 * `GINT_TO_POINTER (n)`, use g_direct_hash() instead.
712 	 *
713 	 * Params:
714 	 *     v = a pointer to a #gint key
715 	 *
716 	 * Returns: a hash value corresponding to the key.
717 	 */
718 	public static uint intHash(void* v)
719 	{
720 		return g_int_hash(v);
721 	}
722 
723 	/**
724 	 * Compares two strings for byte-by-byte equality and returns %TRUE
725 	 * if they are equal. It can be passed to g_hash_table_new() as the
726 	 * @key_equal_func parameter, when using non-%NULL strings as keys in a
727 	 * #GHashTable.
728 	 *
729 	 * Note that this function is primarily meant as a hash table comparison
730 	 * function. For a general-purpose, %NULL-safe string comparison function,
731 	 * see g_strcmp0().
732 	 *
733 	 * Params:
734 	 *     v1 = a key
735 	 *     v2 = a key to compare with @v1
736 	 *
737 	 * Returns: %TRUE if the two keys match
738 	 */
739 	public static bool strEqual(void* v1, void* v2)
740 	{
741 		return g_str_equal(v1, v2) != 0;
742 	}
743 
744 	/**
745 	 * Converts a string to a hash value.
746 	 *
747 	 * This function implements the widely used "djb" hash apparently
748 	 * posted by Daniel Bernstein to comp.lang.c some time ago.  The 32
749 	 * bit unsigned hash value starts at 5381 and for each byte 'c' in
750 	 * the string, is updated: `hash = hash * 33 + c`. This function
751 	 * uses the signed value of each byte.
752 	 *
753 	 * It can be passed to g_hash_table_new() as the @hash_func parameter,
754 	 * when using non-%NULL strings as keys in a #GHashTable.
755 	 *
756 	 * Note that this function may not be a perfect fit for all use cases.
757 	 * For example, it produces some hash collisions with strings as short
758 	 * as 2.
759 	 *
760 	 * Params:
761 	 *     v = a string key
762 	 *
763 	 * Returns: a hash value corresponding to the key
764 	 */
765 	public static uint strHash(void* v)
766 	{
767 		return g_str_hash(v);
768 	}
769 }