1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/uhash.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,666 @@ 1.4 +/* 1.5 +****************************************************************************** 1.6 +* Copyright (C) 1997-2011, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +****************************************************************************** 1.9 +* Date Name Description 1.10 +* 03/22/00 aliu Adapted from original C++ ICU Hashtable. 1.11 +* 07/06/01 aliu Modified to support int32_t keys on 1.12 +* platforms with sizeof(void*) < 32. 1.13 +****************************************************************************** 1.14 +*/ 1.15 + 1.16 +#ifndef UHASH_H 1.17 +#define UHASH_H 1.18 + 1.19 +#include "unicode/utypes.h" 1.20 +#include "cmemory.h" 1.21 +#include "uelement.h" 1.22 + 1.23 +/** 1.24 + * UHashtable stores key-value pairs and does moderately fast lookup 1.25 + * based on keys. It provides a good tradeoff between access time and 1.26 + * storage space. As elements are added to it, it grows to accomodate 1.27 + * them. By default, the table never shrinks, even if all elements 1.28 + * are removed from it. 1.29 + * 1.30 + * Keys and values are stored as void* pointers. These void* pointers 1.31 + * may be actual pointers to strings, objects, or any other structure 1.32 + * in memory, or they may simply be integral values cast to void*. 1.33 + * UHashtable doesn't care and manipulates them via user-supplied 1.34 + * functions. These functions hash keys, compare keys, delete keys, 1.35 + * and delete values. Some function pointers are optional (may be 1.36 + * NULL); others must be supplied. Several prebuilt functions exist 1.37 + * to handle common key types. 1.38 + * 1.39 + * UHashtable ownership of keys and values is flexible, and controlled 1.40 + * by whether or not the key deleter and value deleter functions are 1.41 + * set. If a void* key is actually a pointer to a deletable object, 1.42 + * then UHashtable can be made to delete that object by setting the 1.43 + * key deleter function pointer to a non-NULL value. If this is done, 1.44 + * then keys passed to uhash_put() are owned by the hashtable and will 1.45 + * be deleted by it at some point, either as keys are replaced, or 1.46 + * when uhash_close() is finally called. The same is true of values 1.47 + * and the value deleter function pointer. Keys passed to methods 1.48 + * other than uhash_put() are never owned by the hashtable. 1.49 + * 1.50 + * NULL values are not allowed. uhash_get() returns NULL to indicate 1.51 + * a key that is not in the table, and having a NULL value in the 1.52 + * table would generate an ambiguous result. If a key and a NULL 1.53 + * value is passed to uhash_put(), this has the effect of doing a 1.54 + * uhash_remove() on that key. This keeps uhash_get(), uhash_count(), 1.55 + * and uhash_nextElement() consistent with one another. 1.56 + * 1.57 + * To see everything in a hashtable, use uhash_nextElement() to 1.58 + * iterate through its contents. Each call to this function returns a 1.59 + * UHashElement pointer. A hash element contains a key, value, and 1.60 + * hashcode. During iteration an element may be deleted by calling 1.61 + * uhash_removeElement(); iteration may safely continue thereafter. 1.62 + * The uhash_remove() function may also be safely called in 1.63 + * mid-iteration. However, if uhash_put() is called during iteration 1.64 + * then the iteration will be out of sync. Under no circumstances 1.65 + * should the UHashElement returned by uhash_nextElement be modified 1.66 + * directly. 1.67 + * 1.68 + * By default, the hashtable grows when necessary, but never shrinks, 1.69 + * even if all items are removed. For most applications this is 1.70 + * optimal. However, in a highly dynamic usage where memory is at a 1.71 + * premium, the table can be set to both grow and shrink by calling 1.72 + * uhash_setResizePolicy() with the policy U_GROW_AND_SHRINK. In a 1.73 + * situation where memory is critical and the client wants a table 1.74 + * that does not grow at all, the constant U_FIXED can be used. 1.75 + */ 1.76 + 1.77 +/******************************************************************** 1.78 + * Data Structures 1.79 + ********************************************************************/ 1.80 + 1.81 +U_CDECL_BEGIN 1.82 + 1.83 +/** 1.84 + * A key or value within a UHashtable. 1.85 + * The hashing and comparison functions take a pointer to a 1.86 + * UHashTok, but the deleter receives the void* pointer within it. 1.87 + */ 1.88 +typedef UElement UHashTok; 1.89 + 1.90 +/** 1.91 + * This is a single hash element. 1.92 + */ 1.93 +struct UHashElement { 1.94 + /* Reorder these elements to pack nicely if necessary */ 1.95 + int32_t hashcode; 1.96 + UHashTok value; 1.97 + UHashTok key; 1.98 +}; 1.99 +typedef struct UHashElement UHashElement; 1.100 + 1.101 +/** 1.102 + * A hashing function. 1.103 + * @param key A key stored in a hashtable 1.104 + * @return A NON-NEGATIVE hash code for parm. 1.105 + */ 1.106 +typedef int32_t U_CALLCONV UHashFunction(const UHashTok key); 1.107 + 1.108 +/** 1.109 + * A key equality (boolean) comparison function. 1.110 + */ 1.111 +typedef UElementsAreEqual UKeyComparator; 1.112 + 1.113 +/** 1.114 + * A value equality (boolean) comparison function. 1.115 + */ 1.116 +typedef UElementsAreEqual UValueComparator; 1.117 + 1.118 +/* see cmemory.h for UObjectDeleter and uprv_deleteUObject() */ 1.119 + 1.120 +/** 1.121 + * This specifies whether or not, and how, the hastable resizes itself. 1.122 + * See uhash_setResizePolicy(). 1.123 + */ 1.124 +enum UHashResizePolicy { 1.125 + U_GROW, /* Grow on demand, do not shrink */ 1.126 + U_GROW_AND_SHRINK, /* Grow and shrink on demand */ 1.127 + U_FIXED /* Never change size */ 1.128 +}; 1.129 + 1.130 +/** 1.131 + * The UHashtable struct. Clients should treat this as an opaque data 1.132 + * type and manipulate it only through the uhash_... API. 1.133 + */ 1.134 +struct UHashtable { 1.135 + 1.136 + /* Main key-value pair storage array */ 1.137 + 1.138 + UHashElement *elements; 1.139 + 1.140 + /* Function pointers */ 1.141 + 1.142 + UHashFunction *keyHasher; /* Computes hash from key. 1.143 + * Never null. */ 1.144 + UKeyComparator *keyComparator; /* Compares keys for equality. 1.145 + * Never null. */ 1.146 + UValueComparator *valueComparator; /* Compares the values for equality */ 1.147 + 1.148 + UObjectDeleter *keyDeleter; /* Deletes keys when required. 1.149 + * If NULL won't do anything */ 1.150 + UObjectDeleter *valueDeleter; /* Deletes values when required. 1.151 + * If NULL won't do anything */ 1.152 + 1.153 + /* Size parameters */ 1.154 + 1.155 + int32_t count; /* The number of key-value pairs in this table. 1.156 + * 0 <= count <= length. In practice we 1.157 + * never let count == length (see code). */ 1.158 + int32_t length; /* The physical size of the arrays hashes, keys 1.159 + * and values. Must be prime. */ 1.160 + 1.161 + /* Rehashing thresholds */ 1.162 + 1.163 + int32_t highWaterMark; /* If count > highWaterMark, rehash */ 1.164 + int32_t lowWaterMark; /* If count < lowWaterMark, rehash */ 1.165 + float highWaterRatio; /* 0..1; high water as a fraction of length */ 1.166 + float lowWaterRatio; /* 0..1; low water as a fraction of length */ 1.167 + 1.168 + int8_t primeIndex; /* Index into our prime table for length. 1.169 + * length == PRIMES[primeIndex] */ 1.170 + UBool allocated; /* Was this UHashtable allocated? */ 1.171 +}; 1.172 +typedef struct UHashtable UHashtable; 1.173 + 1.174 +U_CDECL_END 1.175 + 1.176 +/******************************************************************** 1.177 + * API 1.178 + ********************************************************************/ 1.179 + 1.180 +/** 1.181 + * Initialize a new UHashtable. 1.182 + * @param keyHash A pointer to the key hashing function. Must not be 1.183 + * NULL. 1.184 + * @param keyComp A pointer to the function that compares keys. Must 1.185 + * not be NULL. 1.186 + * @param status A pointer to an UErrorCode to receive any errors. 1.187 + * @return A pointer to a UHashtable, or 0 if an error occurred. 1.188 + * @see uhash_openSize 1.189 + */ 1.190 +U_CAPI UHashtable* U_EXPORT2 1.191 +uhash_open(UHashFunction *keyHash, 1.192 + UKeyComparator *keyComp, 1.193 + UValueComparator *valueComp, 1.194 + UErrorCode *status); 1.195 + 1.196 +/** 1.197 + * Initialize a new UHashtable with a given initial size. 1.198 + * @param keyHash A pointer to the key hashing function. Must not be 1.199 + * NULL. 1.200 + * @param keyComp A pointer to the function that compares keys. Must 1.201 + * not be NULL. 1.202 + * @param size The initial capacity of this hash table. 1.203 + * @param status A pointer to an UErrorCode to receive any errors. 1.204 + * @return A pointer to a UHashtable, or 0 if an error occurred. 1.205 + * @see uhash_open 1.206 + */ 1.207 +U_CAPI UHashtable* U_EXPORT2 1.208 +uhash_openSize(UHashFunction *keyHash, 1.209 + UKeyComparator *keyComp, 1.210 + UValueComparator *valueComp, 1.211 + int32_t size, 1.212 + UErrorCode *status); 1.213 + 1.214 +/** 1.215 + * Initialize an existing UHashtable. 1.216 + * @param keyHash A pointer to the key hashing function. Must not be 1.217 + * NULL. 1.218 + * @param keyComp A pointer to the function that compares keys. Must 1.219 + * not be NULL. 1.220 + * @param status A pointer to an UErrorCode to receive any errors. 1.221 + * @return A pointer to a UHashtable, or 0 if an error occurred. 1.222 + * @see uhash_openSize 1.223 + */ 1.224 +U_CAPI UHashtable* U_EXPORT2 1.225 +uhash_init(UHashtable *hash, 1.226 + UHashFunction *keyHash, 1.227 + UKeyComparator *keyComp, 1.228 + UValueComparator *valueComp, 1.229 + UErrorCode *status); 1.230 + 1.231 +/** 1.232 + * Close a UHashtable, releasing the memory used. 1.233 + * @param hash The UHashtable to close. If hash is NULL no operation is performed. 1.234 + */ 1.235 +U_CAPI void U_EXPORT2 1.236 +uhash_close(UHashtable *hash); 1.237 + 1.238 + 1.239 + 1.240 +/** 1.241 + * Set the function used to hash keys. 1.242 + * @param hash The UHashtable to set 1.243 + * @param fn the function to be used hash keys; must not be NULL 1.244 + * @return the previous key hasher; non-NULL 1.245 + */ 1.246 +U_CAPI UHashFunction *U_EXPORT2 1.247 +uhash_setKeyHasher(UHashtable *hash, UHashFunction *fn); 1.248 + 1.249 +/** 1.250 + * Set the function used to compare keys. The default comparison is a 1.251 + * void* pointer comparison. 1.252 + * @param hash The UHashtable to set 1.253 + * @param fn the function to be used compare keys; must not be NULL 1.254 + * @return the previous key comparator; non-NULL 1.255 + */ 1.256 +U_CAPI UKeyComparator *U_EXPORT2 1.257 +uhash_setKeyComparator(UHashtable *hash, UKeyComparator *fn); 1.258 + 1.259 +/** 1.260 + * Set the function used to compare values. The default comparison is a 1.261 + * void* pointer comparison. 1.262 + * @param hash The UHashtable to set 1.263 + * @param fn the function to be used compare keys; must not be NULL 1.264 + * @return the previous key comparator; non-NULL 1.265 + */ 1.266 +U_CAPI UValueComparator *U_EXPORT2 1.267 +uhash_setValueComparator(UHashtable *hash, UValueComparator *fn); 1.268 + 1.269 +/** 1.270 + * Set the function used to delete keys. If this function pointer is 1.271 + * NULL, this hashtable does not delete keys. If it is non-NULL, this 1.272 + * hashtable does delete keys. This function should be set once 1.273 + * before any elements are added to the hashtable and should not be 1.274 + * changed thereafter. 1.275 + * @param hash The UHashtable to set 1.276 + * @param fn the function to be used delete keys, or NULL 1.277 + * @return the previous key deleter; may be NULL 1.278 + */ 1.279 +U_CAPI UObjectDeleter *U_EXPORT2 1.280 +uhash_setKeyDeleter(UHashtable *hash, UObjectDeleter *fn); 1.281 + 1.282 +/** 1.283 + * Set the function used to delete values. If this function pointer 1.284 + * is NULL, this hashtable does not delete values. If it is non-NULL, 1.285 + * this hashtable does delete values. This function should be set 1.286 + * once before any elements are added to the hashtable and should not 1.287 + * be changed thereafter. 1.288 + * @param hash The UHashtable to set 1.289 + * @param fn the function to be used delete values, or NULL 1.290 + * @return the previous value deleter; may be NULL 1.291 + */ 1.292 +U_CAPI UObjectDeleter *U_EXPORT2 1.293 +uhash_setValueDeleter(UHashtable *hash, UObjectDeleter *fn); 1.294 + 1.295 +/** 1.296 + * Specify whether or not, and how, the hastable resizes itself. 1.297 + * By default, tables grow but do not shrink (policy U_GROW). 1.298 + * See enum UHashResizePolicy. 1.299 + * @param hash The UHashtable to set 1.300 + * @param policy The way the hashtable resizes itself, {U_GROW, U_GROW_AND_SHRINK, U_FIXED} 1.301 + */ 1.302 +U_CAPI void U_EXPORT2 1.303 +uhash_setResizePolicy(UHashtable *hash, enum UHashResizePolicy policy); 1.304 + 1.305 +/** 1.306 + * Get the number of key-value pairs stored in a UHashtable. 1.307 + * @param hash The UHashtable to query. 1.308 + * @return The number of key-value pairs stored in hash. 1.309 + */ 1.310 +U_CAPI int32_t U_EXPORT2 1.311 +uhash_count(const UHashtable *hash); 1.312 + 1.313 +/** 1.314 + * Put a (key=pointer, value=pointer) item in a UHashtable. If the 1.315 + * keyDeleter is non-NULL, then the hashtable owns 'key' after this 1.316 + * call. If the valueDeleter is non-NULL, then the hashtable owns 1.317 + * 'value' after this call. Storing a NULL value is the same as 1.318 + * calling uhash_remove(). 1.319 + * @param hash The target UHashtable. 1.320 + * @param key The key to store. 1.321 + * @param value The value to store, may be NULL (see above). 1.322 + * @param status A pointer to an UErrorCode to receive any errors. 1.323 + * @return The previous value, or NULL if none. 1.324 + * @see uhash_get 1.325 + */ 1.326 +U_CAPI void* U_EXPORT2 1.327 +uhash_put(UHashtable *hash, 1.328 + void *key, 1.329 + void *value, 1.330 + UErrorCode *status); 1.331 + 1.332 +/** 1.333 + * Put a (key=integer, value=pointer) item in a UHashtable. 1.334 + * keyDeleter must be NULL. If the valueDeleter is non-NULL, then the 1.335 + * hashtable owns 'value' after this call. Storing a NULL value is 1.336 + * the same as calling uhash_remove(). 1.337 + * @param hash The target UHashtable. 1.338 + * @param key The integer key to store. 1.339 + * @param value The value to store, may be NULL (see above). 1.340 + * @param status A pointer to an UErrorCode to receive any errors. 1.341 + * @return The previous value, or NULL if none. 1.342 + * @see uhash_get 1.343 + */ 1.344 +U_CAPI void* U_EXPORT2 1.345 +uhash_iput(UHashtable *hash, 1.346 + int32_t key, 1.347 + void* value, 1.348 + UErrorCode *status); 1.349 + 1.350 +/** 1.351 + * Put a (key=pointer, value=integer) item in a UHashtable. If the 1.352 + * keyDeleter is non-NULL, then the hashtable owns 'key' after this 1.353 + * call. valueDeleter must be NULL. Storing a 0 value is the same as 1.354 + * calling uhash_remove(). 1.355 + * @param hash The target UHashtable. 1.356 + * @param key The key to store. 1.357 + * @param value The integer value to store. 1.358 + * @param status A pointer to an UErrorCode to receive any errors. 1.359 + * @return The previous value, or 0 if none. 1.360 + * @see uhash_get 1.361 + */ 1.362 +U_CAPI int32_t U_EXPORT2 1.363 +uhash_puti(UHashtable *hash, 1.364 + void* key, 1.365 + int32_t value, 1.366 + UErrorCode *status); 1.367 + 1.368 +/** 1.369 + * Put a (key=integer, value=integer) item in a UHashtable. If the 1.370 + * keyDeleter is non-NULL, then the hashtable owns 'key' after this 1.371 + * call. valueDeleter must be NULL. Storing a 0 value is the same as 1.372 + * calling uhash_remove(). 1.373 + * @param hash The target UHashtable. 1.374 + * @param key The key to store. 1.375 + * @param value The integer value to store. 1.376 + * @param status A pointer to an UErrorCode to receive any errors. 1.377 + * @return The previous value, or 0 if none. 1.378 + * @see uhash_get 1.379 + */ 1.380 +U_CAPI int32_t U_EXPORT2 1.381 +uhash_iputi(UHashtable *hash, 1.382 + int32_t key, 1.383 + int32_t value, 1.384 + UErrorCode *status); 1.385 + 1.386 +/** 1.387 + * Retrieve a pointer value from a UHashtable using a pointer key, 1.388 + * as previously stored by uhash_put(). 1.389 + * @param hash The target UHashtable. 1.390 + * @param key A pointer key stored in a hashtable 1.391 + * @return The requested item, or NULL if not found. 1.392 + */ 1.393 +U_CAPI void* U_EXPORT2 1.394 +uhash_get(const UHashtable *hash, 1.395 + const void *key); 1.396 + 1.397 +/** 1.398 + * Retrieve a pointer value from a UHashtable using a integer key, 1.399 + * as previously stored by uhash_iput(). 1.400 + * @param hash The target UHashtable. 1.401 + * @param key An integer key stored in a hashtable 1.402 + * @return The requested item, or NULL if not found. 1.403 + */ 1.404 +U_CAPI void* U_EXPORT2 1.405 +uhash_iget(const UHashtable *hash, 1.406 + int32_t key); 1.407 + 1.408 +/** 1.409 + * Retrieve an integer value from a UHashtable using a pointer key, 1.410 + * as previously stored by uhash_puti(). 1.411 + * @param hash The target UHashtable. 1.412 + * @param key A pointer key stored in a hashtable 1.413 + * @return The requested item, or 0 if not found. 1.414 + */ 1.415 +U_CAPI int32_t U_EXPORT2 1.416 +uhash_geti(const UHashtable *hash, 1.417 + const void* key); 1.418 +/** 1.419 + * Retrieve an integer value from a UHashtable using an integer key, 1.420 + * as previously stored by uhash_iputi(). 1.421 + * @param hash The target UHashtable. 1.422 + * @param key An integer key stored in a hashtable 1.423 + * @return The requested item, or 0 if not found. 1.424 + */ 1.425 +U_CAPI int32_t U_EXPORT2 1.426 +uhash_igeti(const UHashtable *hash, 1.427 + int32_t key); 1.428 + 1.429 +/** 1.430 + * Remove an item from a UHashtable stored by uhash_put(). 1.431 + * @param hash The target UHashtable. 1.432 + * @param key A key stored in a hashtable 1.433 + * @return The item removed, or NULL if not found. 1.434 + */ 1.435 +U_CAPI void* U_EXPORT2 1.436 +uhash_remove(UHashtable *hash, 1.437 + const void *key); 1.438 + 1.439 +/** 1.440 + * Remove an item from a UHashtable stored by uhash_iput(). 1.441 + * @param hash The target UHashtable. 1.442 + * @param key An integer key stored in a hashtable 1.443 + * @return The item removed, or NULL if not found. 1.444 + */ 1.445 +U_CAPI void* U_EXPORT2 1.446 +uhash_iremove(UHashtable *hash, 1.447 + int32_t key); 1.448 + 1.449 +/** 1.450 + * Remove an item from a UHashtable stored by uhash_puti(). 1.451 + * @param hash The target UHashtable. 1.452 + * @param key An key stored in a hashtable 1.453 + * @return The item removed, or 0 if not found. 1.454 + */ 1.455 +U_CAPI int32_t U_EXPORT2 1.456 +uhash_removei(UHashtable *hash, 1.457 + const void* key); 1.458 + 1.459 +/** 1.460 + * Remove an item from a UHashtable stored by uhash_iputi(). 1.461 + * @param hash The target UHashtable. 1.462 + * @param key An integer key stored in a hashtable 1.463 + * @return The item removed, or 0 if not found. 1.464 + */ 1.465 +U_CAPI int32_t U_EXPORT2 1.466 +uhash_iremovei(UHashtable *hash, 1.467 + int32_t key); 1.468 + 1.469 +/** 1.470 + * Remove all items from a UHashtable. 1.471 + * @param hash The target UHashtable. 1.472 + */ 1.473 +U_CAPI void U_EXPORT2 1.474 +uhash_removeAll(UHashtable *hash); 1.475 + 1.476 +/** 1.477 + * Locate an element of a UHashtable. The caller must not modify the 1.478 + * returned object. The primary use of this function is to obtain the 1.479 + * stored key when it may not be identical to the search key. For 1.480 + * example, if the compare function is a case-insensitive string 1.481 + * compare, then the hash key may be desired in order to obtain the 1.482 + * canonical case corresponding to a search key. 1.483 + * @param hash The target UHashtable. 1.484 + * @param key A key stored in a hashtable 1.485 + * @return a hash element, or NULL if the key is not found. 1.486 + */ 1.487 +U_CAPI const UHashElement* U_EXPORT2 1.488 +uhash_find(const UHashtable *hash, const void* key); 1.489 + 1.490 +/** 1.491 + * Iterate through the elements of a UHashtable. The caller must not 1.492 + * modify the returned object. However, uhash_removeElement() may be 1.493 + * called during iteration to remove an element from the table. 1.494 + * Iteration may safely be resumed afterwards. If uhash_put() is 1.495 + * called during iteration the iteration will then be out of sync and 1.496 + * should be restarted. 1.497 + * @param hash The target UHashtable. 1.498 + * @param pos This should be set to -1 initially, and left untouched 1.499 + * thereafter. 1.500 + * @return a hash element, or NULL if no further key-value pairs 1.501 + * exist in the table. 1.502 + */ 1.503 +U_CAPI const UHashElement* U_EXPORT2 1.504 +uhash_nextElement(const UHashtable *hash, 1.505 + int32_t *pos); 1.506 + 1.507 +/** 1.508 + * Remove an element, returned by uhash_nextElement(), from the table. 1.509 + * Iteration may be safely continued afterwards. 1.510 + * @param hash The hashtable 1.511 + * @param e The element, returned by uhash_nextElement(), to remove. 1.512 + * Must not be NULL. Must not be an empty or deleted element (as long 1.513 + * as this was returned by uhash_nextElement() it will not be empty or 1.514 + * deleted). Note: Although this parameter is const, it will be 1.515 + * modified. 1.516 + * @return the value that was removed. 1.517 + */ 1.518 +U_CAPI void* U_EXPORT2 1.519 +uhash_removeElement(UHashtable *hash, const UHashElement* e); 1.520 + 1.521 +/******************************************************************** 1.522 + * UHashTok convenience 1.523 + ********************************************************************/ 1.524 + 1.525 +/** 1.526 + * Return a UHashTok for an integer. 1.527 + * @param i The given integer 1.528 + * @return a UHashTok for an integer. 1.529 + */ 1.530 +/*U_CAPI UHashTok U_EXPORT2 1.531 +uhash_toki(int32_t i);*/ 1.532 + 1.533 +/** 1.534 + * Return a UHashTok for a pointer. 1.535 + * @param p The given pointer 1.536 + * @return a UHashTok for a pointer. 1.537 + */ 1.538 +/*U_CAPI UHashTok U_EXPORT2 1.539 +uhash_tokp(void* p);*/ 1.540 + 1.541 +/******************************************************************** 1.542 + * UChar* and char* Support Functions 1.543 + ********************************************************************/ 1.544 + 1.545 +/** 1.546 + * Generate a hash code for a null-terminated UChar* string. If the 1.547 + * string is not null-terminated do not use this function. Use 1.548 + * together with uhash_compareUChars. 1.549 + * @param key The string (const UChar*) to hash. 1.550 + * @return A hash code for the key. 1.551 + */ 1.552 +U_CAPI int32_t U_EXPORT2 1.553 +uhash_hashUChars(const UHashTok key); 1.554 + 1.555 +/** 1.556 + * Generate a hash code for a null-terminated char* string. If the 1.557 + * string is not null-terminated do not use this function. Use 1.558 + * together with uhash_compareChars. 1.559 + * @param key The string (const char*) to hash. 1.560 + * @return A hash code for the key. 1.561 + */ 1.562 +U_CAPI int32_t U_EXPORT2 1.563 +uhash_hashChars(const UHashTok key); 1.564 + 1.565 +/** 1.566 + * Generate a case-insensitive hash code for a null-terminated char* 1.567 + * string. If the string is not null-terminated do not use this 1.568 + * function. Use together with uhash_compareIChars. 1.569 + * @param key The string (const char*) to hash. 1.570 + * @return A hash code for the key. 1.571 + */ 1.572 +U_CAPI int32_t U_EXPORT2 1.573 +uhash_hashIChars(const UHashTok key); 1.574 + 1.575 +/** 1.576 + * Comparator for null-terminated UChar* strings. Use together with 1.577 + * uhash_hashUChars. 1.578 + * @param key1 The string for comparison 1.579 + * @param key2 The string for comparison 1.580 + * @return true if key1 and key2 are equal, return false otherwise. 1.581 + */ 1.582 +U_CAPI UBool U_EXPORT2 1.583 +uhash_compareUChars(const UHashTok key1, const UHashTok key2); 1.584 + 1.585 +/** 1.586 + * Comparator for null-terminated char* strings. Use together with 1.587 + * uhash_hashChars. 1.588 + * @param key1 The string for comparison 1.589 + * @param key2 The string for comparison 1.590 + * @return true if key1 and key2 are equal, return false otherwise. 1.591 + */ 1.592 +U_CAPI UBool U_EXPORT2 1.593 +uhash_compareChars(const UHashTok key1, const UHashTok key2); 1.594 + 1.595 +/** 1.596 + * Case-insensitive comparator for null-terminated char* strings. Use 1.597 + * together with uhash_hashIChars. 1.598 + * @param key1 The string for comparison 1.599 + * @param key2 The string for comparison 1.600 + * @return true if key1 and key2 are equal, return false otherwise. 1.601 + */ 1.602 +U_CAPI UBool U_EXPORT2 1.603 +uhash_compareIChars(const UHashTok key1, const UHashTok key2); 1.604 + 1.605 +/******************************************************************** 1.606 + * UnicodeString Support Functions 1.607 + ********************************************************************/ 1.608 + 1.609 +/** 1.610 + * Hash function for UnicodeString* keys. 1.611 + * @param key The string (const char*) to hash. 1.612 + * @return A hash code for the key. 1.613 + */ 1.614 +U_CAPI int32_t U_EXPORT2 1.615 +uhash_hashUnicodeString(const UElement key); 1.616 + 1.617 +/** 1.618 + * Hash function for UnicodeString* keys (case insensitive). 1.619 + * Make sure to use together with uhash_compareCaselessUnicodeString. 1.620 + * @param key The string (const char*) to hash. 1.621 + * @return A hash code for the key. 1.622 + */ 1.623 +U_CAPI int32_t U_EXPORT2 1.624 +uhash_hashCaselessUnicodeString(const UElement key); 1.625 + 1.626 +/******************************************************************** 1.627 + * int32_t Support Functions 1.628 + ********************************************************************/ 1.629 + 1.630 +/** 1.631 + * Hash function for 32-bit integer keys. 1.632 + * @param key The string (const char*) to hash. 1.633 + * @return A hash code for the key. 1.634 + */ 1.635 +U_CAPI int32_t U_EXPORT2 1.636 +uhash_hashLong(const UHashTok key); 1.637 + 1.638 +/** 1.639 + * Comparator function for 32-bit integer keys. 1.640 + * @param key1 The integer for comparison 1.641 + * @param Key2 The integer for comparison 1.642 + * @return true if key1 and key2 are equal, return false otherwise 1.643 + */ 1.644 +U_CAPI UBool U_EXPORT2 1.645 +uhash_compareLong(const UHashTok key1, const UHashTok key2); 1.646 + 1.647 +/******************************************************************** 1.648 + * Other Support Functions 1.649 + ********************************************************************/ 1.650 + 1.651 +/** 1.652 + * Deleter for Hashtable objects. 1.653 + * @param obj The object to be deleted 1.654 + */ 1.655 +U_CAPI void U_EXPORT2 1.656 +uhash_deleteHashtable(void *obj); 1.657 + 1.658 +/* Use uprv_free() itself as a deleter for any key or value allocated using uprv_malloc. */ 1.659 + 1.660 +/** 1.661 + * Checks if the given hash tables are equal or not. 1.662 + * @param hash1 1.663 + * @param hash2 1.664 + * @return true if the hashtables are equal and false if not. 1.665 + */ 1.666 +U_CAPI UBool U_EXPORT2 1.667 +uhash_equals(const UHashtable* hash1, const UHashtable* hash2); 1.668 + 1.669 +#endif