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