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