Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

uhash.h

Go to the documentation of this file.
00001 /*
00002 *******************************************************************************
00003 *   Copyright (C) 1997-2000, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 *******************************************************************************
00006 *   Date        Name        Description
00007 *   03/22/00    aliu        Adapted from original C++ ICU Hashtable.
00008 *******************************************************************************
00009 */
00010 
00011 #ifndef UHASH_H
00012 #define UHASH_H
00013 
00014 #include "unicode/utypes.h"
00015 
00070 /********************************************************************
00071  * Data Structures
00072  ********************************************************************/
00073 
00074 U_CDECL_BEGIN
00075 
00081 typedef int32_t (* U_CALLCONV UHashFunction)(const void* key);
00082 
00089 typedef UBool (* U_CALLCONV UKeyComparator)(const void* key1,
00090                                              const void* key2);
00091 
00098 typedef void (* U_CALLCONV UObjectDeleter)(void* obj);
00099 
00106 struct UHashElement {
00107     int32_t  hashcode;
00108     void*    key;
00109     void*    value;
00110 };
00111 typedef struct UHashElement UHashElement;
00112 
00117 enum UHashResizePolicy {
00118     U_GROW,            /* Grow on demand, do not shrink */
00119     U_GROW_AND_SHRINK, /* Grow and shrink on demand */
00120     U_FIXED            /* Never change size */
00121 };
00122 
00127 struct UHashtable {
00128 
00129     /* Main key-value pair storage array */
00130 
00131     UHashElement *elements;
00132 
00133     /* Size parameters */
00134   
00135     int32_t     count;      /* The number of key-value pairs in this table.
00136                              * 0 <= count <= length.  In practice we
00137                              * never let count == length (see code). */
00138     int32_t     length;     /* The physical size of the arrays hashes, keys
00139                              * and values.  Must be prime. */
00140     int32_t     primeIndex;     /* Index into our prime table for length.
00141                                  * length == PRIMES[primeIndex] */
00142 
00143     /* Rehashing thresholds */
00144     
00145     int32_t     highWaterMark;  /* If count > highWaterMark, rehash */
00146     int32_t     lowWaterMark;   /* If count < lowWaterMark, rehash */
00147     float       highWaterRatio; /* 0..1; high water as a fraction of length */
00148     float       lowWaterRatio;  /* 0..1; low water as a fraction of length */
00149     
00150     /* Function pointers */
00151 
00152     UHashFunction keyHasher;      /* Computes hash from key.
00153                                    * Never null. */
00154     UKeyComparator keyComparator; /* Compares keys for equality.
00155                                    * Never null. */
00156     UObjectDeleter keyDeleter;    /* Deletes keys when required.
00157                                    * If NULL won't do anything */
00158     UObjectDeleter valueDeleter;  /* Deletes values when required.
00159                                    * If NULL won't do anything */
00160 };
00161 typedef struct UHashtable UHashtable;
00162 
00163 U_CDECL_END
00164 
00165 /********************************************************************
00166  * API
00167  ********************************************************************/
00168 
00179 U_CAPI UHashtable*
00180 uhash_open(UHashFunction keyHash,
00181            UKeyComparator keyComp,
00182            UErrorCode *status);
00183 
00195 U_CAPI UHashtable*
00196 uhash_openSize(UHashFunction keyHash,
00197                UKeyComparator keyComp,
00198                int32_t size,
00199                UErrorCode *status);
00200 
00205 U_CAPI void
00206 uhash_close(UHashtable *hash);
00207 
00208 
00209 
00215 U_CAPI UHashFunction
00216 uhash_setKeyHasher(UHashtable *hash, UHashFunction fn);
00217 
00224 U_CAPI UKeyComparator
00225 uhash_setKeyComparator(UHashtable *hash, UKeyComparator fn);
00226 
00236 U_CAPI UObjectDeleter
00237 uhash_setKeyDeleter(UHashtable *hash, UObjectDeleter fn);
00238 
00248 U_CAPI UObjectDeleter
00249 uhash_setValueDeleter(UHashtable *hash, UObjectDeleter fn);
00250 
00256 U_CAPI void
00257 uhash_setResizePolicy(UHashtable *hash, enum UHashResizePolicy policy);
00258 
00264 U_CAPI int32_t
00265 uhash_count(const UHashtable *hash);
00266 
00279 U_CAPI void*
00280 uhash_put(UHashtable *hash,
00281           void *key,
00282           void *value,
00283           UErrorCode *status);
00284 
00291 U_CAPI void*
00292 uhash_get(const UHashtable *hash, 
00293           const void *key);
00294 
00301 U_CAPI void*
00302 uhash_remove(UHashtable *hash,
00303              const void *key);
00304 
00309 U_CAPI void
00310 uhash_removeAll(UHashtable *hash);
00311 
00325 U_CAPI const UHashElement*
00326 uhash_nextElement(const UHashtable *hash,
00327                   int32_t *pos);
00328 
00340 U_CAPI void*
00341 uhash_removeElement(UHashtable *hash, const UHashElement* e);
00342 
00343 /********************************************************************
00344  * UChar* and char* Support Functions
00345  ********************************************************************/
00346 
00354 U_CAPI int32_t
00355 uhash_hashUChars(const void *key);
00356 
00364 U_CAPI int32_t
00365 uhash_hashChars(const void *key);
00366 
00367 /* Used by UnicodeString to compute its hashcode - Not public API. */
00368 U_CAPI int32_t
00369 uhash_hashUCharsN(const UChar *key, int32_t length);
00370 
00378 U_CAPI int32_t
00379 uhash_hashIChars(const void *key);
00380 
00385 U_CAPI UBool
00386 uhash_compareUChars(const void *key1, const void *key2);
00387 
00392 U_CAPI UBool
00393 uhash_compareChars(const void *key1, const void *key2);
00394 
00399 U_CAPI UBool
00400 uhash_compareIChars(const void *key1, const void *key2);
00401 
00402 /********************************************************************
00403  * UnicodeString Support Functions
00404  ********************************************************************/
00405 
00409 U_CAPI int32_t
00410 uhash_hashUnicodeString(const void *key);
00411 
00415 U_CAPI UBool
00416 uhash_compareUnicodeString(const void *key1, const void *key2);
00417 
00421 U_CAPI void
00422 uhash_deleteUnicodeString(void *obj);
00423 
00424 /********************************************************************
00425  * int32_t Support Functions
00426  ********************************************************************/
00427 
00431 U_CAPI int32_t
00432 uhash_hashLong(const void *key);
00433 
00437 U_CAPI UBool
00438 uhash_compareLong(const void *key1, const void *key2);
00439 
00440 /********************************************************************
00441  * Other Support Functions
00442  ********************************************************************/
00443 
00448 U_CAPI void
00449 uhash_freeBlock(void *obj);
00450 
00451 #endif

Generated at Tue Dec 5 17:55:35 2000 for ICU by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000