1 /* 2 ****************************************************************************** 3 * Copyright (C) 1997-2010, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 ****************************************************************************** 6 * Date Name Description 7 * 03/22/00 aliu Adapted from original C++ ICU Hashtable. 8 * 07/06/01 aliu Modified to support int32_t keys on 9 * platforms with sizeof(void*) < 32. 10 ****************************************************************************** 11 */ 12 13 #ifndef UHASH_H 14 #define UHASH_H 15 16 #include "unicode/utypes.h" 17 18 /** 19 * UHashtable stores key-value pairs and does moderately fast lookup 20 * based on keys. It provides a good tradeoff between access time and 21 * storage space. As elements are added to it, it grows to accomodate 22 * them. By default, the table never shrinks, even if all elements 23 * are removed from it. 24 * 25 * Keys and values are stored as void* pointers. These void* pointers 26 * may be actual pointers to strings, objects, or any other structure 27 * in memory, or they may simply be integral values cast to void*. 28 * UHashtable doesn't care and manipulates them via user-supplied 29 * functions. These functions hash keys, compare keys, delete keys, 30 * and delete values. Some function pointers are optional (may be 31 * NULL); others must be supplied. Several prebuilt functions exist 32 * to handle common key types. 33 * 34 * UHashtable ownership of keys and values is flexible, and controlled 35 * by whether or not the key deleter and value deleter functions are 36 * set. If a void* key is actually a pointer to a deletable object, 37 * then UHashtable can be made to delete that object by setting the 38 * key deleter function pointer to a non-NULL value. If this is done, 39 * then keys passed to uhash_put() are owned by the hashtable and will 40 * be deleted by it at some point, either as keys are replaced, or 41 * when uhash_close() is finally called. The same is true of values 42 * and the value deleter function pointer. Keys passed to methods 43 * other than uhash_put() are never owned by the hashtable. 44 * 45 * NULL values are not allowed. uhash_get() returns NULL to indicate 46 * a key that is not in the table, and having a NULL value in the 47 * table would generate an ambiguous result. If a key and a NULL 48 * value is passed to uhash_put(), this has the effect of doing a 49 * uhash_remove() on that key. This keeps uhash_get(), uhash_count(), 50 * and uhash_nextElement() consistent with one another. 51 * 52 * To see everything in a hashtable, use uhash_nextElement() to 53 * iterate through its contents. Each call to this function returns a 54 * UHashElement pointer. A hash element contains a key, value, and 55 * hashcode. During iteration an element may be deleted by calling 56 * uhash_removeElement(); iteration may safely continue thereafter. 57 * The uhash_remove() function may also be safely called in 58 * mid-iteration. However, if uhash_put() is called during iteration 59 * then the iteration will be out of sync. Under no circumstances 60 * should the UHashElement returned by uhash_nextElement be modified 61 * directly. 62 * 63 * By default, the hashtable grows when necessary, but never shrinks, 64 * even if all items are removed. For most applications this is 65 * optimal. However, in a highly dynamic usage where memory is at a 66 * premium, the table can be set to both grow and shrink by calling 67 * uhash_setResizePolicy() with the policy U_GROW_AND_SHRINK. In a 68 * situation where memory is critical and the client wants a table 69 * that does not grow at all, the constant U_FIXED can be used. 70 */ 71 72 /******************************************************************** 73 * Data Structures 74 ********************************************************************/ 75 76 U_CDECL_BEGIN 77 78 /** 79 * A key or value within the hashtable. It may be either a 32-bit 80 * integral value or an opaque void* pointer. The void* pointer may 81 * be smaller than 32 bits (e.g. 24 bits) or may be larger (e.g. 64 82 * bits). The hashing and comparison functions take a pointer to a 83 * UHashTok, but the deleter receives the void* pointer within it. 84 * 85 * Because a UHashTok is the size of a native pointer or a 32-bit 86 * integer, we pass it around by value. 87 */ 88 union UHashTok { 89 void* pointer; 90 int32_t integer; 91 }; 92 typedef union UHashTok UHashTok; 93 94 /** 95 * This is a single hash element. 96 */ 97 struct UHashElement { 98 /* Reorder these elements to pack nicely if necessary */ 99 int32_t hashcode; 100 UHashTok value; 101 UHashTok key; 102 }; 103 typedef struct UHashElement UHashElement; 104 105 /** 106 * A hashing function. 107 * @param key A key stored in a hashtable 108 * @return A NON-NEGATIVE hash code for parm. 109 */ 110 typedef int32_t U_CALLCONV UHashFunction(const UHashTok key); 111 112 /** 113 * A key comparison function. 114 * @param key1 A key stored in a hashtable 115 * @param key2 A key stored in a hashtable 116 * @return TRUE if the two keys are equal. 117 */ 118 typedef UBool U_CALLCONV UKeyComparator(const UHashTok key1, 119 const UHashTok key2); 120 /** 121 * A key comparison function. 122 * @param val1 A key stored in a hashtable 123 * @param val2 A key stored in a hashtable 124 * @return TRUE if the two keys are equal. 125 */ 126 typedef UBool U_CALLCONV UValueComparator(const UHashTok val1, 127 const UHashTok val2); 128 /** 129 * A function called by <TT>uhash_remove</TT>, 130 * <TT>uhash_close</TT>, or <TT>uhash_put</TT> to delete 131 * an existing key or value. 132 * @param obj A key or value stored in a hashtable 133 * @see uhash_deleteUObject 134 */ 135 typedef void U_CALLCONV UObjectDeleter(void* obj); 136 137 /** 138 * This specifies whether or not, and how, the hastable resizes itself. 139 * See uhash_setResizePolicy(). 140 */ 141 enum UHashResizePolicy { 142 U_GROW, /* Grow on demand, do not shrink */ 143 U_GROW_AND_SHRINK, /* Grow and shrink on demand */ 144 U_FIXED /* Never change size */ 145 }; 146 147 /** 148 * The UHashtable struct. Clients should treat this as an opaque data 149 * type and manipulate it only through the uhash_... API. 150 */ 151 struct UHashtable { 152 153 /* Main key-value pair storage array */ 154 155 UHashElement *elements; 156 157 /* Function pointers */ 158 159 UHashFunction *keyHasher; /* Computes hash from key. 160 * Never null. */ 161 UKeyComparator *keyComparator; /* Compares keys for equality. 162 * Never null. */ 163 UValueComparator *valueComparator; /* Compares the values for equality */ 164 165 UObjectDeleter *keyDeleter; /* Deletes keys when required. 166 * If NULL won't do anything */ 167 UObjectDeleter *valueDeleter; /* Deletes values when required. 168 * If NULL won't do anything */ 169 170 /* Size parameters */ 171 172 int32_t count; /* The number of key-value pairs in this table. 173 * 0 <= count <= length. In practice we 174 * never let count == length (see code). */ 175 int32_t length; /* The physical size of the arrays hashes, keys 176 * and values. Must be prime. */ 177 178 /* Rehashing thresholds */ 179 180 int32_t highWaterMark; /* If count > highWaterMark, rehash */ 181 int32_t lowWaterMark; /* If count < lowWaterMark, rehash */ 182 float highWaterRatio; /* 0..1; high water as a fraction of length */ 183 float lowWaterRatio; /* 0..1; low water as a fraction of length */ 184 185 int8_t primeIndex; /* Index into our prime table for length. 186 * length == PRIMES[primeIndex] */ 187 UBool allocated; /* Was this UHashtable allocated? */ 188 }; 189 typedef struct UHashtable UHashtable; 190 191 U_CDECL_END 192 193 /******************************************************************** 194 * API 195 ********************************************************************/ 196 197 /** 198 * Initialize a new UHashtable. 199 * @param keyHash A pointer to the key hashing function. Must not be 200 * NULL. 201 * @param keyComp A pointer to the function that compares keys. Must 202 * not be NULL. 203 * @param status A pointer to an UErrorCode to receive any errors. 204 * @return A pointer to a UHashtable, or 0 if an error occurred. 205 * @see uhash_openSize 206 */ 207 U_CAPI UHashtable* U_EXPORT2 208 uhash_open(UHashFunction *keyHash, 209 UKeyComparator *keyComp, 210 UValueComparator *valueComp, 211 UErrorCode *status); 212 213 /** 214 * Initialize a new UHashtable with a given initial size. 215 * @param keyHash A pointer to the key hashing function. Must not be 216 * NULL. 217 * @param keyComp A pointer to the function that compares keys. Must 218 * not be NULL. 219 * @param size The initial capacity of this hash table. 220 * @param status A pointer to an UErrorCode to receive any errors. 221 * @return A pointer to a UHashtable, or 0 if an error occurred. 222 * @see uhash_open 223 */ 224 U_CAPI UHashtable* U_EXPORT2 225 uhash_openSize(UHashFunction *keyHash, 226 UKeyComparator *keyComp, 227 UValueComparator *valueComp, 228 int32_t size, 229 UErrorCode *status); 230 231 /** 232 * Initialize an existing UHashtable. 233 * @param keyHash A pointer to the key hashing function. Must not be 234 * NULL. 235 * @param keyComp A pointer to the function that compares keys. Must 236 * not be NULL. 237 * @param status A pointer to an UErrorCode to receive any errors. 238 * @return A pointer to a UHashtable, or 0 if an error occurred. 239 * @see uhash_openSize 240 */ 241 U_CAPI UHashtable* U_EXPORT2 242 uhash_init(UHashtable *hash, 243 UHashFunction *keyHash, 244 UKeyComparator *keyComp, 245 UValueComparator *valueComp, 246 UErrorCode *status); 247 248 /** 249 * Close a UHashtable, releasing the memory used. 250 * @param hash The UHashtable to close. If hash is NULL no operation is performed. 251 */ 252 U_CAPI void U_EXPORT2 253 uhash_close(UHashtable *hash); 254 255 256 257 /** 258 * Set the function used to hash keys. 259 * @param hash The UHashtable to set 260 * @param fn the function to be used hash keys; must not be NULL 261 * @return the previous key hasher; non-NULL 262 */ 263 U_CAPI UHashFunction *U_EXPORT2 264 uhash_setKeyHasher(UHashtable *hash, UHashFunction *fn); 265 266 /** 267 * Set the function used to compare keys. The default comparison is a 268 * void* pointer comparison. 269 * @param hash The UHashtable to set 270 * @param fn the function to be used compare keys; must not be NULL 271 * @return the previous key comparator; non-NULL 272 */ 273 U_CAPI UKeyComparator *U_EXPORT2 274 uhash_setKeyComparator(UHashtable *hash, UKeyComparator *fn); 275 276 /** 277 * Set the function used to compare values. The default comparison is a 278 * void* pointer comparison. 279 * @param hash The UHashtable to set 280 * @param fn the function to be used compare keys; must not be NULL 281 * @return the previous key comparator; non-NULL 282 */ 283 U_CAPI UValueComparator *U_EXPORT2 284 uhash_setValueComparator(UHashtable *hash, UValueComparator *fn); 285 286 /** 287 * Set the function used to delete keys. If this function pointer is 288 * NULL, this hashtable does not delete keys. If it is non-NULL, this 289 * hashtable does delete keys. This function should be set once 290 * before any elements are added to the hashtable and should not be 291 * changed thereafter. 292 * @param hash The UHashtable to set 293 * @param fn the function to be used delete keys, or NULL 294 * @return the previous key deleter; may be NULL 295 */ 296 U_CAPI UObjectDeleter *U_EXPORT2 297 uhash_setKeyDeleter(UHashtable *hash, UObjectDeleter *fn); 298 299 /** 300 * Set the function used to delete values. If this function pointer 301 * is NULL, this hashtable does not delete values. If it is non-NULL, 302 * this hashtable does delete values. This function should be set 303 * once before any elements are added to the hashtable and should not 304 * be changed thereafter. 305 * @param hash The UHashtable to set 306 * @param fn the function to be used delete values, or NULL 307 * @return the previous value deleter; may be NULL 308 */ 309 U_CAPI UObjectDeleter *U_EXPORT2 310 uhash_setValueDeleter(UHashtable *hash, UObjectDeleter *fn); 311 312 /** 313 * Specify whether or not, and how, the hastable resizes itself. 314 * By default, tables grow but do not shrink (policy U_GROW). 315 * See enum UHashResizePolicy. 316 * @param hash The UHashtable to set 317 * @param policy The way the hashtable resizes itself, {U_GROW, U_GROW_AND_SHRINK, U_FIXED} 318 */ 319 U_CAPI void U_EXPORT2 320 uhash_setResizePolicy(UHashtable *hash, enum UHashResizePolicy policy); 321 322 /** 323 * Get the number of key-value pairs stored in a UHashtable. 324 * @param hash The UHashtable to query. 325 * @return The number of key-value pairs stored in hash. 326 */ 327 U_CAPI int32_t U_EXPORT2 328 uhash_count(const UHashtable *hash); 329 330 /** 331 * Put a (key=pointer, value=pointer) item in a UHashtable. If the 332 * keyDeleter is non-NULL, then the hashtable owns 'key' after this 333 * call. If the valueDeleter is non-NULL, then the hashtable owns 334 * 'value' after this call. Storing a NULL value is the same as 335 * calling uhash_remove(). 336 * @param hash The target UHashtable. 337 * @param key The key to store. 338 * @param value The value to store, may be NULL (see above). 339 * @param status A pointer to an UErrorCode to receive any errors. 340 * @return The previous value, or NULL if none. 341 * @see uhash_get 342 */ 343 U_CAPI void* U_EXPORT2 344 uhash_put(UHashtable *hash, 345 void *key, 346 void *value, 347 UErrorCode *status); 348 349 /** 350 * Put a (key=integer, value=pointer) item in a UHashtable. 351 * keyDeleter must be NULL. If the valueDeleter is non-NULL, then the 352 * hashtable owns 'value' after this call. Storing a NULL value is 353 * the same as calling uhash_remove(). 354 * @param hash The target UHashtable. 355 * @param key The integer key to store. 356 * @param value The value to store, may be NULL (see above). 357 * @param status A pointer to an UErrorCode to receive any errors. 358 * @return The previous value, or NULL if none. 359 * @see uhash_get 360 */ 361 U_CAPI void* U_EXPORT2 362 uhash_iput(UHashtable *hash, 363 int32_t key, 364 void* value, 365 UErrorCode *status); 366 367 /** 368 * Put a (key=pointer, value=integer) item in a UHashtable. If the 369 * keyDeleter is non-NULL, then the hashtable owns 'key' after this 370 * call. valueDeleter must be NULL. Storing a 0 value is the same as 371 * calling uhash_remove(). 372 * @param hash The target UHashtable. 373 * @param key The key to store. 374 * @param value The integer value to store. 375 * @param status A pointer to an UErrorCode to receive any errors. 376 * @return The previous value, or 0 if none. 377 * @see uhash_get 378 */ 379 U_CAPI int32_t U_EXPORT2 380 uhash_puti(UHashtable *hash, 381 void* key, 382 int32_t value, 383 UErrorCode *status); 384 385 /** 386 * Put a (key=integer, value=integer) item in a UHashtable. If the 387 * keyDeleter is non-NULL, then the hashtable owns 'key' after this 388 * call. valueDeleter must be NULL. Storing a 0 value is the same as 389 * calling uhash_remove(). 390 * @param hash The target UHashtable. 391 * @param key The key to store. 392 * @param value The integer value to store. 393 * @param status A pointer to an UErrorCode to receive any errors. 394 * @return The previous value, or 0 if none. 395 * @see uhash_get 396 */ 397 U_CAPI int32_t U_EXPORT2 398 uhash_iputi(UHashtable *hash, 399 int32_t key, 400 int32_t value, 401 UErrorCode *status); 402 403 /** 404 * Retrieve a pointer value from a UHashtable using a pointer key, 405 * as previously stored by uhash_put(). 406 * @param hash The target UHashtable. 407 * @param key A pointer key stored in a hashtable 408 * @return The requested item, or NULL if not found. 409 */ 410 U_CAPI void* U_EXPORT2 411 uhash_get(const UHashtable *hash, 412 const void *key); 413 414 /** 415 * Retrieve a pointer value from a UHashtable using a integer key, 416 * as previously stored by uhash_iput(). 417 * @param hash The target UHashtable. 418 * @param key An integer key stored in a hashtable 419 * @return The requested item, or NULL if not found. 420 */ 421 U_CAPI void* U_EXPORT2 422 uhash_iget(const UHashtable *hash, 423 int32_t key); 424 425 /** 426 * Retrieve an integer value from a UHashtable using a pointer key, 427 * as previously stored by uhash_puti(). 428 * @param hash The target UHashtable. 429 * @param key A pointer key stored in a hashtable 430 * @return The requested item, or 0 if not found. 431 */ 432 U_CAPI int32_t U_EXPORT2 433 uhash_geti(const UHashtable *hash, 434 const void* key); 435 /** 436 * Retrieve an integer value from a UHashtable using an integer key, 437 * as previously stored by uhash_iputi(). 438 * @param hash The target UHashtable. 439 * @param key An integer key stored in a hashtable 440 * @return The requested item, or 0 if not found. 441 */ 442 U_CAPI int32_t U_EXPORT2 443 uhash_igeti(const UHashtable *hash, 444 int32_t key); 445 446 /** 447 * Remove an item from a UHashtable stored by uhash_put(). 448 * @param hash The target UHashtable. 449 * @param key A key stored in a hashtable 450 * @return The item removed, or NULL if not found. 451 */ 452 U_CAPI void* U_EXPORT2 453 uhash_remove(UHashtable *hash, 454 const void *key); 455 456 /** 457 * Remove an item from a UHashtable stored by uhash_iput(). 458 * @param hash The target UHashtable. 459 * @param key An integer key stored in a hashtable 460 * @return The item removed, or NULL if not found. 461 */ 462 U_CAPI void* U_EXPORT2 463 uhash_iremove(UHashtable *hash, 464 int32_t key); 465 466 /** 467 * Remove an item from a UHashtable stored by uhash_puti(). 468 * @param hash The target UHashtable. 469 * @param key An key stored in a hashtable 470 * @return The item removed, or 0 if not found. 471 */ 472 U_CAPI int32_t U_EXPORT2 473 uhash_removei(UHashtable *hash, 474 const void* key); 475 476 /** 477 * Remove an item from a UHashtable stored by uhash_iputi(). 478 * @param hash The target UHashtable. 479 * @param key An integer key stored in a hashtable 480 * @return The item removed, or 0 if not found. 481 */ 482 U_CAPI int32_t U_EXPORT2 483 uhash_iremovei(UHashtable *hash, 484 int32_t key); 485 486 /** 487 * Remove all items from a UHashtable. 488 * @param hash The target UHashtable. 489 */ 490 U_CAPI void U_EXPORT2 491 uhash_removeAll(UHashtable *hash); 492 493 /** 494 * Locate an element of a UHashtable. The caller must not modify the 495 * returned object. The primary use of this function is to obtain the 496 * stored key when it may not be identical to the search key. For 497 * example, if the compare function is a case-insensitive string 498 * compare, then the hash key may be desired in order to obtain the 499 * canonical case corresponding to a search key. 500 * @param hash The target UHashtable. 501 * @param key A key stored in a hashtable 502 * @return a hash element, or NULL if the key is not found. 503 */ 504 U_CAPI const UHashElement* U_EXPORT2 505 uhash_find(const UHashtable *hash, const void* key); 506 507 /** 508 * Iterate through the elements of a UHashtable. The caller must not 509 * modify the returned object. However, uhash_removeElement() may be 510 * called during iteration to remove an element from the table. 511 * Iteration may safely be resumed afterwards. If uhash_put() is 512 * called during iteration the iteration will then be out of sync and 513 * should be restarted. 514 * @param hash The target UHashtable. 515 * @param pos This should be set to -1 initially, and left untouched 516 * thereafter. 517 * @return a hash element, or NULL if no further key-value pairs 518 * exist in the table. 519 */ 520 U_CAPI const UHashElement* U_EXPORT2 521 uhash_nextElement(const UHashtable *hash, 522 int32_t *pos); 523 524 /** 525 * Remove an element, returned by uhash_nextElement(), from the table. 526 * Iteration may be safely continued afterwards. 527 * @param hash The hashtable 528 * @param e The element, returned by uhash_nextElement(), to remove. 529 * Must not be NULL. Must not be an empty or deleted element (as long 530 * as this was returned by uhash_nextElement() it will not be empty or 531 * deleted). Note: Although this parameter is const, it will be 532 * modified. 533 * @return the value that was removed. 534 */ 535 U_CAPI void* U_EXPORT2 536 uhash_removeElement(UHashtable *hash, const UHashElement* e); 537 538 /******************************************************************** 539 * UHashTok convenience 540 ********************************************************************/ 541 542 /** 543 * Return a UHashTok for an integer. 544 * @param i The given integer 545 * @return a UHashTok for an integer. 546 */ 547 /*U_CAPI UHashTok U_EXPORT2 548 uhash_toki(int32_t i);*/ 549 550 /** 551 * Return a UHashTok for a pointer. 552 * @param p The given pointer 553 * @return a UHashTok for a pointer. 554 */ 555 /*U_CAPI UHashTok U_EXPORT2 556 uhash_tokp(void* p);*/ 557 558 /******************************************************************** 559 * UChar* and char* Support Functions 560 ********************************************************************/ 561 562 /** 563 * Generate a hash code for a null-terminated UChar* string. If the 564 * string is not null-terminated do not use this function. Use 565 * together with uhash_compareUChars. 566 * @param key The string (const UChar*) to hash. 567 * @return A hash code for the key. 568 */ 569 U_CAPI int32_t U_EXPORT2 570 uhash_hashUChars(const UHashTok key); 571 572 /** 573 * Generate a hash code for a null-terminated char* string. If the 574 * string is not null-terminated do not use this function. Use 575 * together with uhash_compareChars. 576 * @param key The string (const char*) to hash. 577 * @return A hash code for the key. 578 */ 579 U_CAPI int32_t U_EXPORT2 580 uhash_hashChars(const UHashTok key); 581 582 /* Used by UnicodeString to compute its hashcode - Not public API. */ 583 U_CAPI int32_t U_EXPORT2 584 uhash_hashUCharsN(const UChar *key, int32_t length); 585 586 U_CAPI int32_t U_EXPORT2 587 uhash_hashCharsN(const char *key, int32_t length); 588 589 /** 590 * Generate a case-insensitive hash code for a null-terminated char* 591 * string. If the string is not null-terminated do not use this 592 * function. Use together with uhash_compareIChars. 593 * @param key The string (const char*) to hash. 594 * @return A hash code for the key. 595 */ 596 U_CAPI int32_t U_EXPORT2 597 uhash_hashIChars(const UHashTok key); 598 599 /** 600 * Comparator for null-terminated UChar* strings. Use together with 601 * uhash_hashUChars. 602 * @param key1 The string for comparison 603 * @param key2 The string for comparison 604 * @return true if key1 and key2 are equal, return false otherwise. 605 */ 606 U_CAPI UBool U_EXPORT2 607 uhash_compareUChars(const UHashTok key1, const UHashTok key2); 608 609 /** 610 * Comparator for null-terminated char* strings. Use together with 611 * uhash_hashChars. 612 * @param key1 The string for comparison 613 * @param key2 The string for comparison 614 * @return true if key1 and key2 are equal, return false otherwise. 615 */ 616 U_CAPI UBool U_EXPORT2 617 uhash_compareChars(const UHashTok key1, const UHashTok key2); 618 619 /** 620 * Case-insensitive comparator for null-terminated char* strings. Use 621 * together with uhash_hashIChars. 622 * @param key1 The string for comparison 623 * @param key2 The string for comparison 624 * @return true if key1 and key2 are equal, return false otherwise. 625 */ 626 U_CAPI UBool U_EXPORT2 627 uhash_compareIChars(const UHashTok key1, const UHashTok key2); 628 629 /******************************************************************** 630 * UnicodeString Support Functions 631 ********************************************************************/ 632 633 /** 634 * Hash function for UnicodeString* keys. 635 * @param key The string (const char*) to hash. 636 * @return A hash code for the key. 637 */ 638 U_CAPI int32_t U_EXPORT2 639 uhash_hashUnicodeString(const UHashTok key); 640 641 /** 642 * Hash function for UnicodeString* keys (case insensitive). 643 * Make sure to use together with uhash_compareCaselessUnicodeString. 644 * @param key The string (const char*) to hash. 645 * @return A hash code for the key. 646 */ 647 U_CAPI int32_t U_EXPORT2 648 uhash_hashCaselessUnicodeString(const UHashTok key); 649 650 /** 651 * Comparator function for UnicodeString* keys. 652 * @param key1 The string for comparison 653 * @param key2 The string for comparison 654 * @return true if key1 and key2 are equal, return false otherwise. 655 */ 656 U_CAPI UBool U_EXPORT2 657 uhash_compareUnicodeString(const UHashTok key1, const UHashTok key2); 658 659 /** 660 * Comparator function for UnicodeString* keys (case insensitive). 661 * Make sure to use together with uhash_hashCaselessUnicodeString. 662 * @param key1 The string for comparison 663 * @param key2 The string for comparison 664 * @return true if key1 and key2 are equal, return false otherwise. 665 */ 666 U_CAPI UBool U_EXPORT2 667 uhash_compareCaselessUnicodeString(const UHashTok key1, const UHashTok key2); 668 669 /** 670 * Deleter function for UnicodeString* keys or values. 671 * @param obj The object to be deleted 672 */ 673 U_CAPI void U_EXPORT2 674 uhash_deleteUnicodeString(void *obj); 675 676 /******************************************************************** 677 * int32_t Support Functions 678 ********************************************************************/ 679 680 /** 681 * Hash function for 32-bit integer keys. 682 * @param key The string (const char*) to hash. 683 * @return A hash code for the key. 684 */ 685 U_CAPI int32_t U_EXPORT2 686 uhash_hashLong(const UHashTok key); 687 688 /** 689 * Comparator function for 32-bit integer keys. 690 * @param key1 The integer for comparison 691 * @param Key2 The integer for comparison 692 * @return true if key1 and key2 are equal, return false otherwise 693 */ 694 U_CAPI UBool U_EXPORT2 695 uhash_compareLong(const UHashTok key1, const UHashTok key2); 696 697 /******************************************************************** 698 * Other Support Functions 699 ********************************************************************/ 700 701 /** 702 * Deleter for Hashtable objects. 703 * @param obj The object to be deleted 704 */ 705 U_CAPI void U_EXPORT2 706 uhash_deleteHashtable(void *obj); 707 708 /** 709 * Deleter for UObject instances. 710 * @param obj The object to be deleted 711 */ 712 U_CAPI void U_EXPORT2 713 uhash_deleteUObject(void *obj); 714 715 /** 716 * Deleter for any key or value allocated using uprv_malloc. Calls 717 * uprv_free. 718 * @param obj The object to be deleted 719 */ 720 U_CAPI void U_EXPORT2 721 uhash_freeBlock(void *obj); 722 723 /** 724 * Checks if the given hash tables are equal or not. 725 * @param hash1 726 * @param hash2 727 * @return true if the hashtables are equal and false if not. 728 */ 729 U_CAPI UBool U_EXPORT2 730 uhash_equals(const UHashtable* hash1, const UHashtable* hash2); 731 732 #endif 733