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