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 * Conversion parameters: 26 * inFile = glib-Hash-Tables.html 27 * outPack = glib 28 * outFile = HashTable 29 * strct = GHashTable 30 * realStrct= 31 * ctorStrct= 32 * clss = HashTable 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_hash_table_ 41 * omit structs: 42 * omit prefixes: 43 * - g_hash_table_iter_ 44 * omit code: 45 * omit signals: 46 * imports: 47 * - glib.ListG 48 * - gtkc.paths 49 * - gtkc.Loader 50 * structWrap: 51 * - GHashTable* -> HashTable 52 * - GList* -> ListG 53 * module aliases: 54 * local aliases: 55 * overrides: 56 */ 57 58 module glib.HashTable; 59 60 public import gtkc.glibtypes; 61 62 private import gtkc.glib; 63 private import glib.ConstructionException; 64 65 66 private import glib.ListG; 67 private import gtkc.paths; 68 private import gtkc.Loader; 69 70 71 72 73 /** 74 * A GHashTable provides associations between keys and values which is 75 * optimized so that given a key, the associated value can be found 76 * very quickly. 77 * 78 * Note that neither keys nor values are copied when inserted into the 79 * GHashTable, so they must exist for the lifetime of the GHashTable. 80 * This means that the use of static strings is OK, but temporary 81 * strings (i.e. those created in buffers and those returned by GTK+ 82 * widgets) should be copied with g_strdup() before being inserted. 83 * 84 * If keys or values are dynamically allocated, you must be careful to 85 * ensure that they are freed when they are removed from the 86 * GHashTable, and also when they are overwritten by new insertions 87 * into the GHashTable. It is also not advisable to mix static strings 88 * and dynamically-allocated strings in a GHashTable, because it then 89 * becomes difficult to determine whether the string should be freed. 90 * 91 * To create a GHashTable, use g_hash_table_new(). 92 * 93 * To insert a key and value into a GHashTable, use 94 * g_hash_table_insert(). 95 * 96 * To lookup a value corresponding to a given key, use 97 * g_hash_table_lookup() and g_hash_table_lookup_extended(). 98 * 99 * g_hash_table_lookup_extended() can also be used to simply 100 * check if a key is present in the hash table. 101 * 102 * To remove a key and value, use g_hash_table_remove(). 103 * 104 * To call a function for each key and value pair use 105 * g_hash_table_foreach() or use a iterator to iterate over the 106 * key/value pairs in the hash table, see GHashTableIter. 107 * 108 * To destroy a GHashTable use g_hash_table_destroy(). 109 * 110 * A common use-case for hash tables is to store information about a 111 * set of keys, without associating any particular value with each 112 * key. GHashTable optimizes one way of doing so: If you store only 113 * key-value pairs where key == value, then GHashTable does not 114 * allocate memory to store the values, which can be a considerable 115 * space saving, if your set is large. The functions 116 * g_hash_table_add() and g_hash_table_contains() are designed to be 117 * used when using GHashTable this way. 118 */ 119 public class HashTable 120 { 121 122 /** the main Gtk struct */ 123 protected GHashTable* gHashTable; 124 125 126 public GHashTable* getHashTableStruct() 127 { 128 return gHashTable; 129 } 130 131 132 /** the main Gtk struct as a void* */ 133 protected void* getStruct() 134 { 135 return cast(void*)gHashTable; 136 } 137 138 /** 139 * Sets our main struct and passes it to the parent class 140 */ 141 public this (GHashTable* gHashTable) 142 { 143 this.gHashTable = gHashTable; 144 } 145 146 ~this () 147 { 148 if ( Linker.isLoaded(LIBRARY.GLIB) && gHashTable !is null ) 149 { 150 g_hash_table_unref(gHashTable); 151 } 152 } 153 154 /** 155 */ 156 157 /** 158 * Creates a new GHashTable with a reference count of 1. 159 * Hash values returned by hash_func are used to determine where keys 160 * are stored within the GHashTable data structure. The g_direct_hash(), 161 * g_int_hash(), g_int64_hash(), g_double_hash() and g_str_hash() 162 * functions are provided for some common types of keys. 163 * If hash_func is NULL, g_direct_hash() is used. 164 * key_equal_func is used when looking up keys in the GHashTable. 165 * The g_direct_equal(), g_int_equal(), g_int64_equal(), g_double_equal() 166 * and g_str_equal() functions are provided for the most common types 167 * of keys. If key_equal_func is NULL, keys are compared directly in 168 * a similar fashion to g_direct_equal(), but without the overhead of 169 * a function call. 170 * Params: 171 * hashFunc = a function to create a hash value from a key 172 * keyEqualFunc = a function to check two keys for equality 173 * Throws: ConstructionException GTK+ fails to create the object. 174 */ 175 public this (GHashFunc hashFunc, GEqualFunc keyEqualFunc) 176 { 177 // GHashTable * g_hash_table_new (GHashFunc hash_func, GEqualFunc key_equal_func); 178 auto p = g_hash_table_new(hashFunc, keyEqualFunc); 179 if(p is null) 180 { 181 throw new ConstructionException("null returned by g_hash_table_new(hashFunc, keyEqualFunc)"); 182 } 183 this(cast(GHashTable*) p); 184 } 185 186 /** 187 * Creates a new GHashTable like g_hash_table_new() with a reference 188 * count of 1 and allows to specify functions to free the memory 189 * allocated for the key and value that get called when removing the 190 * entry from the GHashTable. 191 * Params: 192 * hashFunc = a function to create a hash value from a key 193 * keyEqualFunc = a function to check two keys for equality 194 * keyDestroyFunc = a function to free the memory allocated for the key 195 * used when removing the entry from the GHashTable, or NULL 196 * if you don't want to supply such a function. [allow-none] 197 * valueDestroyFunc = a function to free the memory allocated for the 198 * value used when removing the entry from the GHashTable, or NULL 199 * if you don't want to supply such a function. [allow-none] 200 * Throws: ConstructionException GTK+ fails to create the object. 201 */ 202 public this (GHashFunc hashFunc, GEqualFunc keyEqualFunc, GDestroyNotify keyDestroyFunc, GDestroyNotify valueDestroyFunc) 203 { 204 // GHashTable * g_hash_table_new_full (GHashFunc hash_func, GEqualFunc key_equal_func, GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func); 205 auto p = g_hash_table_new_full(hashFunc, keyEqualFunc, keyDestroyFunc, valueDestroyFunc); 206 if(p is null) 207 { 208 throw new ConstructionException("null returned by g_hash_table_new_full(hashFunc, keyEqualFunc, keyDestroyFunc, valueDestroyFunc)"); 209 } 210 this(cast(GHashTable*) p); 211 } 212 213 /** 214 * Inserts a new key and value into a GHashTable. 215 * If the key already exists in the GHashTable its current 216 * value is replaced with the new value. If you supplied a 217 * value_destroy_func when creating the GHashTable, the old 218 * value is freed using that function. If you supplied a 219 * key_destroy_func when creating the GHashTable, the passed 220 * key is freed using that function. 221 * Params: 222 * key = a key to insert 223 * value = the value to associate with the key 224 */ 225 public void insert(void* key, void* value) 226 { 227 // void g_hash_table_insert (GHashTable *hash_table, gpointer key, gpointer value); 228 g_hash_table_insert(gHashTable, key, value); 229 } 230 231 /** 232 * Inserts a new key and value into a GHashTable similar to 233 * g_hash_table_insert(). The difference is that if the key 234 * already exists in the GHashTable, it gets replaced by the 235 * new key. If you supplied a value_destroy_func when creating 236 * the GHashTable, the old value is freed using that function. 237 * If you supplied a key_destroy_func when creating the 238 * GHashTable, the old key is freed using that function. 239 * Params: 240 * key = a key to insert 241 * value = the value to associate with the key 242 */ 243 public void replace(void* key, void* value) 244 { 245 // void g_hash_table_replace (GHashTable *hash_table, gpointer key, gpointer value); 246 g_hash_table_replace(gHashTable, key, value); 247 } 248 249 /** 250 * This is a convenience function for using a GHashTable as a set. It 251 * is equivalent to calling g_hash_table_replace() with key as both the 252 * key and the value. 253 * When a hash table only ever contains keys that have themselves as the 254 * corresponding value it is able to be stored more efficiently. See 255 * the discussion in the section description. 256 * Since 2.32 257 * Params: 258 * key = a key to insert 259 */ 260 public void add(void* key) 261 { 262 // void g_hash_table_add (GHashTable *hash_table, gpointer key); 263 g_hash_table_add(gHashTable, key); 264 } 265 266 /** 267 * Checks if key is in hash_table. 268 * Since 2.32 269 * Params: 270 * key = a key to check 271 */ 272 public int contains(void* key) 273 { 274 // gboolean g_hash_table_contains (GHashTable *hash_table, gconstpointer key); 275 return g_hash_table_contains(gHashTable, key); 276 } 277 278 /** 279 * Returns the number of elements contained in the GHashTable. 280 * Returns: the number of key/value pairs in the GHashTable. 281 */ 282 public uint size() 283 { 284 // guint g_hash_table_size (GHashTable *hash_table); 285 return g_hash_table_size(gHashTable); 286 } 287 288 /** 289 * Looks up a key in a GHashTable. Note that this function cannot 290 * distinguish between a key that is not present and one which is present 291 * and has the value NULL. If you need this distinction, use 292 * g_hash_table_lookup_extended(). 293 * Params: 294 * key = the key to look up 295 * Returns: the associated value, or NULL if the key is not found. [allow-none] 296 */ 297 public void* lookup(void* key) 298 { 299 // gpointer g_hash_table_lookup (GHashTable *hash_table, gconstpointer key); 300 return g_hash_table_lookup(gHashTable, key); 301 } 302 303 /** 304 * Looks up a key in the GHashTable, returning the original key and the 305 * associated value and a gboolean which is TRUE if the key was found. This 306 * is useful if you need to free the memory allocated for the original key, 307 * for example before calling g_hash_table_remove(). 308 * You can actually pass NULL for lookup_key to test 309 * whether the NULL key exists, provided the hash and equal functions 310 * of hash_table are NULL-safe. 311 * Params: 312 * lookupKey = the key to look up 313 * origKey = return location for the original key, or NULL. [allow-none] 314 * value = return location for the value associated with the key, or NULL. [allow-none] 315 * Returns: TRUE if the key was found in the GHashTable 316 */ 317 public int lookupExtended(void* lookupKey, void** origKey, void** value) 318 { 319 // gboolean g_hash_table_lookup_extended (GHashTable *hash_table, gconstpointer lookup_key, gpointer *orig_key, gpointer *value); 320 return g_hash_table_lookup_extended(gHashTable, lookupKey, origKey, value); 321 } 322 323 /** 324 * Calls the given function for each of the key/value pairs in the 325 * GHashTable. The function is passed the key and value of each 326 * pair, and the given user_data parameter. The hash table may not 327 * be modified while iterating over it (you can't add/remove 328 * items). To remove all items matching a predicate, use 329 * g_hash_table_foreach_remove(). 330 * See g_hash_table_find() for performance caveats for linear 331 * order searches in contrast to g_hash_table_lookup(). 332 * Params: 333 * func = the function to call for each key/value pair 334 * userData = user data to pass to the function 335 */ 336 public void foreac(GHFunc func, void* userData) 337 { 338 // void g_hash_table_foreach (GHashTable *hash_table, GHFunc func, gpointer user_data); 339 g_hash_table_foreach(gHashTable, func, userData); 340 } 341 342 /** 343 * Calls the given function for key/value pairs in the GHashTable 344 * until predicate returns TRUE. The function is passed the key 345 * and value of each pair, and the given user_data parameter. The 346 * hash table may not be modified while iterating over it (you can't 347 * add/remove items). 348 * Note, that hash tables are really only optimized for forward 349 * lookups, i.e. g_hash_table_lookup(). So code that frequently issues 350 * g_hash_table_find() or g_hash_table_foreach() (e.g. in the order of 351 * once per every entry in a hash table) should probably be reworked 352 * to use additional or different data structures for reverse lookups 353 * (keep in mind that an O(n) find/foreach operation issued for all n 354 * values in a hash table ends up needing O(n*n) operations). 355 * Since 2.4 356 * Params: 357 * predicate = function to test the key/value pairs for a certain property 358 * userData = user data to pass to the function 359 * Returns: The value of the first key/value pair is returned, for which predicate evaluates to TRUE. If no pair with the requested property is found, NULL is returned. [allow-none] 360 */ 361 public void* find(GHRFunc predicate, void* userData) 362 { 363 // gpointer g_hash_table_find (GHashTable *hash_table, GHRFunc predicate, gpointer user_data); 364 return g_hash_table_find(gHashTable, predicate, userData); 365 } 366 367 /** 368 * Removes a key and its associated value from a GHashTable. 369 * If the GHashTable was created using g_hash_table_new_full(), the 370 * key and value are freed using the supplied destroy functions, otherwise 371 * you have to make sure that any dynamically allocated values are freed 372 * yourself. 373 * Params: 374 * key = the key to remove 375 * Returns: TRUE if the key was found and removed from the GHashTable 376 */ 377 public int remove(void* key) 378 { 379 // gboolean g_hash_table_remove (GHashTable *hash_table, gconstpointer key); 380 return g_hash_table_remove(gHashTable, key); 381 } 382 383 /** 384 * Removes a key and its associated value from a GHashTable without 385 * calling the key and value destroy functions. 386 * Params: 387 * key = the key to remove 388 * Returns: TRUE if the key was found and removed from the GHashTable 389 */ 390 public int steal(void* key) 391 { 392 // gboolean g_hash_table_steal (GHashTable *hash_table, gconstpointer key); 393 return g_hash_table_steal(gHashTable, key); 394 } 395 396 /** 397 * Calls the given function for each key/value pair in the 398 * GHashTable. If the function returns TRUE, then the key/value 399 * pair is removed from the GHashTable. If you supplied key or 400 * value destroy functions when creating the GHashTable, they are 401 * used to free the memory allocated for the removed keys and values. 402 * See GHashTableIter for an alternative way to loop over the 403 * key/value pairs in the hash table. 404 * Params: 405 * func = the function to call for each key/value pair 406 * userData = user data to pass to the function 407 * Returns: the number of key/value pairs removed 408 */ 409 public uint foreachRemove(GHRFunc func, void* userData) 410 { 411 // guint g_hash_table_foreach_remove (GHashTable *hash_table, GHRFunc func, gpointer user_data); 412 return g_hash_table_foreach_remove(gHashTable, func, userData); 413 } 414 415 /** 416 * Calls the given function for each key/value pair in the 417 * GHashTable. If the function returns TRUE, then the key/value 418 * pair is removed from the GHashTable, but no key or value 419 * destroy functions are called. 420 * See GHashTableIter for an alternative way to loop over the 421 * key/value pairs in the hash table. 422 * Params: 423 * func = the function to call for each key/value pair 424 * userData = user data to pass to the function 425 * Returns: the number of key/value pairs removed. 426 */ 427 public uint foreachSteal(GHRFunc func, void* userData) 428 { 429 // guint g_hash_table_foreach_steal (GHashTable *hash_table, GHRFunc func, gpointer user_data); 430 return g_hash_table_foreach_steal(gHashTable, func, userData); 431 } 432 433 /** 434 * Removes all keys and their associated values from a GHashTable. 435 * If the GHashTable was created using g_hash_table_new_full(), 436 * the keys and values are freed using the supplied destroy functions, 437 * otherwise you have to make sure that any dynamically allocated 438 * values are freed yourself. 439 * Since 2.12 440 */ 441 public void removeAll() 442 { 443 // void g_hash_table_remove_all (GHashTable *hash_table); 444 g_hash_table_remove_all(gHashTable); 445 } 446 447 /** 448 * Removes all keys and their associated values from a GHashTable 449 * without calling the key and value destroy functions. 450 * Since 2.12 451 */ 452 public void stealAll() 453 { 454 // void g_hash_table_steal_all (GHashTable *hash_table); 455 g_hash_table_steal_all(gHashTable); 456 } 457 458 /** 459 * Retrieves every key inside hash_table. The returned data is valid 460 * until changes to the hash release those keys. 461 * Since 2.14 462 * Returns: 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. 463 */ 464 public ListG getKeys() 465 { 466 // GList * g_hash_table_get_keys (GHashTable *hash_table); 467 auto p = g_hash_table_get_keys(gHashTable); 468 469 if(p is null) 470 { 471 return null; 472 } 473 474 return new ListG(cast(GList*) p); 475 } 476 477 /** 478 * Retrieves every value inside hash_table. The returned data 479 * is valid until hash_table is modified. 480 * Since 2.14 481 * Returns: 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. 482 */ 483 public ListG getValues() 484 { 485 // GList * g_hash_table_get_values (GHashTable *hash_table); 486 auto p = g_hash_table_get_values(gHashTable); 487 488 if(p is null) 489 { 490 return null; 491 } 492 493 return new ListG(cast(GList*) p); 494 } 495 496 /** 497 * Destroys all keys and values in the GHashTable and decrements its 498 * reference count by 1. If keys and/or values are dynamically allocated, 499 * you should either free them first or create the GHashTable with destroy 500 * notifiers using g_hash_table_new_full(). In the latter case the destroy 501 * functions you supplied will be called on all keys and values during the 502 * destruction phase. 503 */ 504 public void destroy() 505 { 506 // void g_hash_table_destroy (GHashTable *hash_table); 507 g_hash_table_destroy(gHashTable); 508 } 509 510 /** 511 * Atomically increments the reference count of hash_table by one. 512 * This function is MT-safe and may be called from any thread. 513 * Since 2.10 514 * Returns: the passed in GHashTable 515 */ 516 public HashTable doref() 517 { 518 // GHashTable * g_hash_table_ref (GHashTable *hash_table); 519 auto p = g_hash_table_ref(gHashTable); 520 521 if(p is null) 522 { 523 return null; 524 } 525 526 return new HashTable(cast(GHashTable*) p); 527 } 528 529 /** 530 * Atomically decrements the reference count of hash_table by one. 531 * If the reference count drops to 0, all keys and values will be 532 * destroyed, and all memory allocated by the hash table is released. 533 * This function is MT-safe and may be called from any thread. 534 * Since 2.10 535 */ 536 public void unref() 537 { 538 // void g_hash_table_unref (GHashTable *hash_table); 539 g_hash_table_unref(gHashTable); 540 } 541 542 /** 543 * Compares two gpointer arguments and returns TRUE if they are equal. 544 * It can be passed to g_hash_table_new() as the key_equal_func 545 * parameter, when using opaque pointers compared by pointer value as keys 546 * in a GHashTable. 547 * This equality function is also appropriate for keys that are integers stored 548 * in pointers, such as GINT_TO_POINTER (n). 549 * Params: 550 * v1 = a key. [allow-none] 551 * v2 = a key to compare with v1. [allow-none] 552 * Returns: TRUE if the two keys match. 553 */ 554 public static int gDirectEqual(void* v1, void* v2) 555 { 556 // gboolean g_direct_equal (gconstpointer v1, gconstpointer v2); 557 return g_direct_equal(v1, v2); 558 } 559 560 /** 561 * Converts a gpointer to a hash value. 562 * It can be passed to g_hash_table_new() as the hash_func parameter, 563 * when using opaque pointers compared by pointer value as keys in a 564 * GHashTable. 565 * This hash function is also appropriate for keys that are integers stored 566 * in pointers, such as GINT_TO_POINTER (n). 567 * Params: 568 * v = a gpointer key. [allow-none] 569 * Returns: a hash value corresponding to the key. 570 */ 571 public static uint gDirectHash(void* v) 572 { 573 // guint g_direct_hash (gconstpointer v); 574 return g_direct_hash(v); 575 } 576 577 /** 578 * Compares the two gint values being pointed to and returns 579 * TRUE if they are equal. 580 * It can be passed to g_hash_table_new() as the key_equal_func 581 * parameter, when using non-NULL pointers to integers as keys in a 582 * GHashTable. 583 * Params: 584 * v1 = a pointer to a gint key 585 * v2 = a pointer to a gint key to compare with v1 586 * Returns: TRUE if the two keys match. 587 */ 588 public static int gIntEqual(void* v1, void* v2) 589 { 590 // gboolean g_int_equal (gconstpointer v1, gconstpointer v2); 591 return g_int_equal(v1, v2); 592 } 593 594 /** 595 * Converts a pointer to a gint to a hash value. 596 * It can be passed to g_hash_table_new() as the hash_func parameter, 597 * when using non-NULL pointers to integer values as keys in a GHashTable. 598 * Params: 599 * v = a pointer to a gint key 600 * Returns: a hash value corresponding to the key. 601 */ 602 public static uint gIntHash(void* v) 603 { 604 // guint g_int_hash (gconstpointer v); 605 return g_int_hash(v); 606 } 607 608 /** 609 * Compares the two gint64 values being pointed to and returns 610 * TRUE if they are equal. 611 * It can be passed to g_hash_table_new() as the key_equal_func 612 * parameter, when using non-NULL pointers to 64-bit integers as keys in a 613 * GHashTable. 614 * Since 2.22 615 * Params: 616 * v1 = a pointer to a gint64 key 617 * v2 = a pointer to a gint64 key to compare with v1 618 * Returns: TRUE if the two keys match. 619 */ 620 public static int gInt64_Equal(void* v1, void* v2) 621 { 622 // gboolean g_int64_equal (gconstpointer v1, gconstpointer v2); 623 return g_int64_equal(v1, v2); 624 } 625 626 /** 627 * Converts a pointer to a gint64 to a hash value. 628 * It can be passed to g_hash_table_new() as the hash_func parameter, 629 * when using non-NULL pointers to 64-bit integer values as keys in a 630 * GHashTable. 631 * Since 2.22 632 * Params: 633 * v = a pointer to a gint64 key 634 * Returns: a hash value corresponding to the key. 635 */ 636 public static uint gInt64_Hash(void* v) 637 { 638 // guint g_int64_hash (gconstpointer v); 639 return g_int64_hash(v); 640 } 641 642 /** 643 * Compares the two gdouble values being pointed to and returns 644 * TRUE if they are equal. 645 * It can be passed to g_hash_table_new() as the key_equal_func 646 * parameter, when using non-NULL pointers to doubles as keys in a 647 * GHashTable. 648 * Since 2.22 649 * Params: 650 * v1 = a pointer to a gdouble key 651 * v2 = a pointer to a gdouble key to compare with v1 652 * Returns: TRUE if the two keys match. 653 */ 654 public static int gDoubleEqual(void* v1, void* v2) 655 { 656 // gboolean g_double_equal (gconstpointer v1, gconstpointer v2); 657 return g_double_equal(v1, v2); 658 } 659 660 /** 661 * Converts a pointer to a gdouble to a hash value. 662 * It can be passed to g_hash_table_new() as the hash_func parameter, 663 * It can be passed to g_hash_table_new() as the hash_func parameter, 664 * when using non-NULL pointers to doubles as keys in a GHashTable. 665 * Since 2.22 666 * Params: 667 * v = a pointer to a gdouble key 668 * Returns: a hash value corresponding to the key. 669 */ 670 public static uint gDoubleHash(void* v) 671 { 672 // guint g_double_hash (gconstpointer v); 673 return g_double_hash(v); 674 } 675 676 /** 677 * Compares two strings for byte-by-byte equality and returns TRUE 678 * if they are equal. It can be passed to g_hash_table_new() as the 679 * key_equal_func parameter, when using non-NULL strings as keys in a 680 * GHashTable. 681 * Note that this function is primarily meant as a hash table comparison 682 * function. For a general-purpose, NULL-safe string comparison function, 683 * see g_strcmp0(). 684 * Params: 685 * v1 = a key 686 * v2 = a key to compare with v1 687 * Returns: TRUE if the two keys match 688 */ 689 public static int gStrEqual(void* v1, void* v2) 690 { 691 // gboolean g_str_equal (gconstpointer v1, gconstpointer v2); 692 return g_str_equal(v1, v2); 693 } 694 695 /** 696 * Converts a string to a hash value. 697 * This function implements the widely used "djb" hash apparently posted 698 * by Daniel Bernstein to comp.lang.c some time ago. The 32 bit 699 * unsigned hash value starts at 5381 and for each byte 'c' in the 700 * string, is updated: hash = hash * 33 + c. This 701 * function uses the signed value of each byte. 702 * It can be passed to g_hash_table_new() as the hash_func parameter, 703 * when using non-NULL strings as keys in a GHashTable. 704 * Params: 705 * v = a string key 706 * Returns: a hash value corresponding to the key 707 */ 708 public static uint gStrHash(void* v) 709 { 710 // guint g_str_hash (gconstpointer v); 711 return g_str_hash(v); 712 } 713 }