diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index 3ea0068caa..c3a665d2b8 100644 --- a/icu4c/source/common/locid.cpp +++ b/icu4c/source/common/locid.cpp @@ -479,7 +479,7 @@ Locale& Locale::init(const char* localeID) int32_t Locale::hashCode() const { - UHashKey hashKey; + UHashTok hashKey; hashKey.pointer = fullName; return uhash_hashChars(hashKey); } diff --git a/icu4c/source/common/ucnv_bld.c b/icu4c/source/common/ucnv_bld.c index 173f687f3e..8d7ba4de66 100644 --- a/icu4c/source/common/ucnv_bld.c +++ b/icu4c/source/common/ucnv_bld.c @@ -560,7 +560,7 @@ ucnv_flushCache () umtx_lock (NULL); while ((e = uhash_nextElement (SHARED_DATA_HASHTABLE, &pos)) != NULL) { - mySharedData = (UConverterSharedData *) e->value; + mySharedData = (UConverterSharedData *) e->value.pointer; /*deletes only if reference counter == 0 */ if (mySharedData->referenceCounter == 0) { diff --git a/icu4c/source/common/uhash.c b/icu4c/source/common/uhash.c index a2bc897de8..39065f3b23 100644 --- a/icu4c/source/common/uhash.c +++ b/icu4c/source/common/uhash.c @@ -109,13 +109,14 @@ static const float RESIZE_POLICY_RATIO_TABLE[6] = { #define IS_EMPTY_OR_DELETED(x) ((x) < 0) -/* This macro expects a UHashKey.pointer as its keypointer parameter */ -#define HASH_DELETE_KEY_VALUE(hash, keypointer, value) \ +/* This macro expects a UHashTok.pointer as its keypointer and + valuepointer parameters */ +#define HASH_DELETE_KEY_VALUE(hash, keypointer, valuepointer) \ if (hash->keyDeleter != NULL && keypointer != NULL) { \ (*hash->keyDeleter)(keypointer); \ } \ - if (hash->valueDeleter != NULL && value != NULL) { \ - (*hash->valueDeleter)(value); \ + if (hash->valueDeleter != NULL && valuepointer != NULL) { \ + (*hash->valueDeleter)(valuepointer); \ } /******************************************************************** @@ -154,21 +155,21 @@ static void _uhash_allocate(UHashtable *hash, int32_t primeIndex, static void _uhash_rehash(UHashtable *hash); -static UHashElement* _uhash_find(const UHashtable *hash, UHashKey key, +static UHashElement* _uhash_find(const UHashtable *hash, UHashTok key, int32_t hashcode); -static void* _uhash_put(UHashtable *hash, - UHashKey key, - void* value, +static UHashTok _uhash_put(UHashtable *hash, + UHashTok key, + UHashTok value, UErrorCode *status); -static void* _uhash_remove(UHashtable *hash, - UHashKey key); +static UHashTok _uhash_remove(UHashtable *hash, + UHashTok key); -static void* _uhash_internalRemoveElement(UHashtable *hash, UHashElement* e); +static UHashTok _uhash_internalRemoveElement(UHashtable *hash, UHashElement* e); -static void* _uhash_setElement(UHashtable* hash, UHashElement* e, - int32_t hashcode, UHashKey key, void* value); +static UHashTok _uhash_setElement(UHashtable* hash, UHashElement* e, + int32_t hashcode, UHashTok key, UHashTok value); static void _uhash_internalSetResizePolicy(UHashtable *hash, enum UHashResizePolicy policy); @@ -205,7 +206,7 @@ uhash_close(UHashtable *hash) { int32_t pos=-1; UHashElement *e; while ((e = (UHashElement*) uhash_nextElement(hash, &pos)) != NULL) { - HASH_DELETE_KEY_VALUE(hash, e->key.pointer, e->value); + HASH_DELETE_KEY_VALUE(hash, e->key.pointer, e->value.pointer); } } uprv_free(hash->elements); @@ -258,17 +259,17 @@ uhash_count(const UHashtable *hash) { U_CAPI void* uhash_get(const UHashtable *hash, const void* key) { - UHashKey keyholder; + UHashTok keyholder; keyholder.pointer = (void*) key; - return _uhash_find(hash, keyholder, hash->keyHasher(keyholder))->value; + return _uhash_find(hash, keyholder, hash->keyHasher(keyholder))->value.pointer; } U_CAPI void* -uhash_geti(const UHashtable *hash, +uhash_iget(const UHashtable *hash, int32_t key) { - UHashKey keyholder; + UHashTok keyholder; keyholder.integer = key; - return _uhash_find(hash, keyholder, hash->keyHasher(keyholder))->value; + return _uhash_find(hash, keyholder, hash->keyHasher(keyholder))->value.pointer; } U_CAPI void* @@ -276,35 +277,37 @@ uhash_put(UHashtable *hash, void* key, void* value, UErrorCode *status) { - UHashKey keyholder; + UHashTok keyholder, valueholder; keyholder.pointer = key; - return _uhash_put(hash, keyholder, value, status); + valueholder.pointer = value; + return _uhash_put(hash, keyholder, valueholder, status).pointer; } void* -uhash_puti(UHashtable *hash, +uhash_iput(UHashtable *hash, int32_t key, void* value, UErrorCode *status) { - UHashKey keyholder; + UHashTok keyholder, valueholder; keyholder.integer = key; - return _uhash_put(hash, keyholder, value, status); + valueholder.pointer = value; + return _uhash_put(hash, keyholder, valueholder, status).pointer; } U_CAPI void* uhash_remove(UHashtable *hash, const void* key) { - UHashKey keyholder; + UHashTok keyholder; keyholder.pointer = (void*) key; - return _uhash_remove(hash, keyholder); + return _uhash_remove(hash, keyholder).pointer; } U_CAPI void* -uhash_removei(UHashtable *hash, +uhash_iremove(UHashtable *hash, int32_t key) { - UHashKey keyholder; + UHashTok keyholder; keyholder.integer = key; - return _uhash_remove(hash, keyholder); + return _uhash_remove(hash, keyholder).pointer; } U_CAPI void @@ -322,7 +325,7 @@ uhash_removeAll(UHashtable *hash) { U_CAPI const UHashElement* uhash_find(const UHashtable *hash, const void* key) { - UHashKey keyholder; + UHashTok keyholder; const UHashElement *e; keyholder.pointer = (void*) key; e = _uhash_find(hash, keyholder, hash->keyHasher(keyholder)); @@ -352,7 +355,7 @@ uhash_removeElement(UHashtable *hash, const UHashElement* e) { assert(hash != NULL); assert(e != NULL); if (!IS_EMPTY_OR_DELETED(e->hashcode)) { - return _uhash_internalRemoveElement(hash, (UHashElement*) e); + return _uhash_internalRemoveElement(hash, (UHashElement*) e).pointer; } return NULL; } @@ -385,7 +388,7 @@ uhash_removeElement(UHashtable *hash, const UHashElement* e) { return hash U_CAPI int32_t -uhash_hashUChars(const UHashKey key) { +uhash_hashUChars(const UHashTok key) { STRING_HASH(UChar, key.pointer, u_strlen(p), *p); } @@ -396,12 +399,12 @@ uhash_hashUCharsN(const UChar *str, int32_t length) { } U_CAPI int32_t -uhash_hashChars(const UHashKey key) { +uhash_hashChars(const UHashTok key) { STRING_HASH(uint8_t, key.pointer, uprv_strlen((char*)p), *p); } U_CAPI int32_t -uhash_hashIChars(const UHashKey key) { +uhash_hashIChars(const UHashTok key) { STRING_HASH(uint8_t, key.pointer, uprv_strlen((char*)p), uprv_tolower(*p)); } @@ -410,7 +413,7 @@ uhash_hashIChars(const UHashKey key) { ********************************************************************/ U_CAPI UBool -uhash_compareUChars(const UHashKey key1, const UHashKey key2) { +uhash_compareUChars(const UHashTok key1, const UHashTok key2) { const UChar *p1 = (const UChar*) key1.pointer; const UChar *p2 = (const UChar*) key2.pointer; if (p1 == p2) { @@ -427,7 +430,7 @@ uhash_compareUChars(const UHashKey key1, const UHashKey key2) { } U_CAPI UBool -uhash_compareChars(const UHashKey key1, const UHashKey key2) { +uhash_compareChars(const UHashTok key1, const UHashTok key2) { const char *p1 = (const char*) key1.pointer; const char *p2 = (const char*) key2.pointer; if (p1 == p2) { @@ -444,7 +447,7 @@ uhash_compareChars(const UHashKey key1, const UHashKey key2) { } U_CAPI UBool -uhash_compareIChars(const UHashKey key1, const UHashKey key2) { +uhash_compareIChars(const UHashTok key1, const UHashTok key2) { const char *p1 = (const char*) key1.pointer; const char *p2 = (const char*) key2.pointer; if (p1 == p2) { @@ -465,12 +468,12 @@ uhash_compareIChars(const UHashKey key1, const UHashKey key2) { ********************************************************************/ U_CAPI int32_t -uhash_hashLong(const UHashKey key) { +uhash_hashLong(const UHashTok key) { return key.integer; } U_CAPI UBool -uhash_compareLong(const UHashKey key1, const UHashKey key2) { +uhash_compareLong(const UHashTok key1, const UHashTok key2) { return (UBool)(key1.integer == key2.integer); } @@ -534,7 +537,7 @@ _uhash_allocate(UHashtable *hash, UErrorCode *status) { UHashElement *p, *limit; - UHashKey emptykey; + UHashTok emptytok; if (U_FAILURE(*status)) return; @@ -551,13 +554,13 @@ _uhash_allocate(UHashtable *hash, return; } - emptykey.pointer = NULL; /* Only one of these two is needed */ - emptykey.integer = 0; /* but we don't know which one. */ + emptytok.pointer = NULL; /* Only one of these two is needed */ + emptytok.integer = 0; /* but we don't know which one. */ limit = p + hash->length; while (p < limit) { - p->key = emptykey; - p->value = NULL; + p->key = emptytok; + p->value = emptytok; p->hashcode = HASH_EMPTY; ++p; } @@ -649,7 +652,7 @@ _uhash_rehash(UHashtable *hash) { * hash) is relatively prime to the table length. */ static UHashElement* -_uhash_find(const UHashtable *hash, UHashKey key, +_uhash_find(const UHashtable *hash, UHashTok key, int32_t hashcode) { int32_t firstDeleted = -1; /* assume invalid index */ @@ -700,10 +703,10 @@ _uhash_find(const UHashtable *hash, UHashKey key, return &(hash->elements[theIndex]); } -static void* +static UHashTok _uhash_put(UHashtable *hash, - UHashKey key, - void* value, + UHashTok key, + UHashTok value, UErrorCode *status) { /* Put finds the position in the table for the new value. If the @@ -713,12 +716,13 @@ _uhash_put(UHashtable *hash, */ int32_t hashcode; UHashElement* e; + UHashTok emptytok; if (U_FAILURE(*status)) { goto err; } assert(hash != NULL); - if (value == NULL) { + if (value.pointer == NULL) { /* Disallow storage of NULL values, since NULL is returned by * get() to indicate an absent key. Storing NULL == removing. */ @@ -760,13 +764,14 @@ _uhash_put(UHashtable *hash, * value arguments, and we must be sure to delete the key and/or * value in all cases, even upon failure. */ - HASH_DELETE_KEY_VALUE(hash, key.pointer, value); - return NULL; + HASH_DELETE_KEY_VALUE(hash, key.pointer, value.pointer); + emptytok.pointer = NULL; emptytok.integer = 0; + return emptytok; } -static void* +static UHashTok _uhash_remove(UHashtable *hash, - UHashKey key) { + UHashTok key) { /* First find the position of the key in the table. If the object * has not been removed already, remove it. If the user wanted * keys deleted, then delete it also. We have to put a special @@ -774,9 +779,10 @@ _uhash_remove(UHashtable *hash, * deleted, since when we do a find, we have to continue PAST any * deleted values. */ - void* result = NULL; + UHashTok result; UHashElement* e = _uhash_find(hash, key, hash->keyHasher(key)); assert(e != NULL); + result.pointer = NULL; result.integer = 0; if (!IS_EMPTY_OR_DELETED(e->hashcode)) { result = _uhash_internalRemoveElement(hash, e); if (hash->count < hash->lowWaterMark) { @@ -786,24 +792,24 @@ _uhash_remove(UHashtable *hash, return result; } -static void* +static UHashTok _uhash_setElement(UHashtable *hash, UHashElement* e, - int32_t hashcode, UHashKey key, void* value) { + int32_t hashcode, UHashTok key, UHashTok value) { - void* oldKey = e->key.pointer; - void* oldValue = e->value; - if (hash->keyDeleter != NULL && oldKey != NULL && - oldKey != key.pointer) { /* Avoid double deletion */ - (*hash->keyDeleter)(oldKey); + void* oldKeyPtr = e->key.pointer; + UHashTok oldValue = e->value; + if (hash->keyDeleter != NULL && oldKeyPtr != NULL && + oldKeyPtr != key.pointer) { /* Avoid double deletion */ + (*hash->keyDeleter)(oldKeyPtr); } - if (oldValue == value) { /* Avoid double deletion */ - oldValue = NULL; + if (hash->valueDeleter != NULL) { + if (oldValue.pointer != NULL && + oldValue.pointer != value.pointer) { /* Avoid double deletion */ + (*hash->valueDeleter)(oldValue.pointer); + } + oldValue.pointer = NULL; } - if (hash->valueDeleter != NULL && oldValue != NULL) { - (*hash->valueDeleter)(oldValue); - oldValue = NULL; - } - /* Compilers should copy the UHashKey union correctly. If they do + /* Compilers should copy the UHashTok union correctly. If they do * not, replace this line with e->key.pointer = key.pointer for * platforms with sizeof(void*) >= sizeof(int32_t), e->key.integer * = key.integer otherwise. */ @@ -816,13 +822,13 @@ _uhash_setElement(UHashtable *hash, UHashElement* e, /** * Assumes that the given element is not empty or deleted. */ -static void* +static UHashTok _uhash_internalRemoveElement(UHashtable *hash, UHashElement* e) { - UHashKey emptykey; + UHashTok empty; assert(!IS_EMPTY_OR_DELETED(e->hashcode)); --hash->count; - emptykey.pointer = NULL; emptykey.integer = 0; - return _uhash_setElement(hash, e, HASH_DELETED, emptykey, NULL); + empty.pointer = NULL; empty.integer = 0; + return _uhash_setElement(hash, e, HASH_DELETED, empty, empty); } static void diff --git a/icu4c/source/common/uhash.h b/icu4c/source/common/uhash.h index 3113508d26..69f071f91c 100644 --- a/icu4c/source/common/uhash.h +++ b/icu4c/source/common/uhash.h @@ -76,20 +76,20 @@ U_CDECL_BEGIN /** - * A key within the hashtable. The key may be either a 32-bit + * A key or value within the hashtable. It may be either a 32-bit * integral value or an opaque void* pointer. The void* pointer may * be smaller than 32 bits (e.g. 24 bits) or may be larger (e.g. 64 * bits). The hashing and comparison functions take a pointer to a - * UHashKey, but the deleter receives the void* pointer within it. + * UHashTok, but the deleter receives the void* pointer within it. * - * Because a UHashKey is the size of a native pointer or a 32-bit + * Because a UHashTok is the size of a native pointer or a 32-bit * integer, we pass it around by value. */ -union UHashKey { +union UHashTok { void* pointer; int32_t integer; }; -typedef union UHashKey UHashKey; +typedef union UHashTok UHashTok; /** * This is a single hash element. @@ -97,8 +97,8 @@ typedef union UHashKey UHashKey; struct UHashElement { /* Reorder these elements to pack nicely if necessary */ int32_t hashcode; - void* value; - UHashKey key; + UHashTok value; + UHashTok key; }; typedef struct UHashElement UHashElement; @@ -107,7 +107,7 @@ typedef struct UHashElement UHashElement; * @param key A key stored in a hashtable * @return A NON-NEGATIVE hash code for parm. */ -typedef int32_t (* U_CALLCONV UHashFunction)(const UHashKey key); +typedef int32_t (* U_CALLCONV UHashFunction)(const UHashTok key); /** * A key comparison function. @@ -115,8 +115,8 @@ typedef int32_t (* U_CALLCONV UHashFunction)(const UHashKey key); * @param key2 A key stored in a hashtable * @return TRUE if the two keys are equal. */ -typedef UBool (* U_CALLCONV UKeyComparator)(const UHashKey key1, - const UHashKey key2); +typedef UBool (* U_CALLCONV UKeyComparator)(const UHashTok key1, + const UHashTok key2); /** * A function called by uhash_remove, @@ -300,7 +300,7 @@ uhash_put(UHashtable *hash, /* NEW */ U_CAPI void* -uhash_puti(UHashtable *hash, +uhash_iput(UHashtable *hash, int32_t key, void* value, UErrorCode *status); @@ -317,7 +317,7 @@ uhash_get(const UHashtable *hash, /* NEW */ U_CAPI void* -uhash_geti(const UHashtable *hash, +uhash_iget(const UHashtable *hash, int32_t key); /** @@ -332,7 +332,7 @@ uhash_remove(UHashtable *hash, /* NEW */ U_CAPI void* -uhash_removei(UHashtable *hash, +uhash_iremove(UHashtable *hash, int32_t key); /** @@ -399,7 +399,7 @@ uhash_removeElement(UHashtable *hash, const UHashElement* e); * @return A hash code for the key. */ U_CAPI int32_t -uhash_hashUChars(const UHashKey key); +uhash_hashUChars(const UHashTok key); /** * Generate a hash code for a null-terminated char* string. If the @@ -409,7 +409,7 @@ uhash_hashUChars(const UHashKey key); * @return A hash code for the key. */ U_CAPI int32_t -uhash_hashChars(const UHashKey key); +uhash_hashChars(const UHashTok key); /* Used by UnicodeString to compute its hashcode - Not public API. */ U_CAPI int32_t @@ -423,28 +423,28 @@ uhash_hashUCharsN(const UChar *key, int32_t length); * @return A hash code for the key. */ U_CAPI int32_t -uhash_hashIChars(const UHashKey key); +uhash_hashIChars(const UHashTok key); /** * Comparator for null-terminated UChar* strings. Use together with * uhash_hashUChars. */ U_CAPI UBool -uhash_compareUChars(const UHashKey key1, const UHashKey key2); +uhash_compareUChars(const UHashTok key1, const UHashTok key2); /** * Comparator for null-terminated char* strings. Use together with * uhash_hashChars. */ U_CAPI UBool -uhash_compareChars(const UHashKey key1, const UHashKey key2); +uhash_compareChars(const UHashTok key1, const UHashTok key2); /** * Case-insensitive comparator for null-terminated char* strings. Use * together with uhash_hashIChars. */ U_CAPI UBool -uhash_compareIChars(const UHashKey key1, const UHashKey key2); +uhash_compareIChars(const UHashTok key1, const UHashTok key2); /******************************************************************** * UnicodeString Support Functions @@ -454,27 +454,27 @@ uhash_compareIChars(const UHashKey key1, const UHashKey key2); * Hash function for UnicodeString* keys. */ U_CAPI int32_t -uhash_hashUnicodeString(const UHashKey key); +uhash_hashUnicodeString(const UHashTok key); /** * Hash function for UnicodeString* keys (case insensitive). * Make sure to use together with uhash_compareCaselessUnicodeString. */ U_CAPI int32_t -uhash_hashCaselessUnicodeString(const UHashKey key); +uhash_hashCaselessUnicodeString(const UHashTok key); /** * Comparator function for UnicodeString* keys. */ U_CAPI UBool -uhash_compareUnicodeString(const UHashKey key1, const UHashKey key2); +uhash_compareUnicodeString(const UHashTok key1, const UHashTok key2); /** * Comparator function for UnicodeString* keys (case insensitive). * Make sure to use together with uhash_hashCaselessUnicodeString. */ U_CAPI UBool -uhash_compareCaselessUnicodeString(const UHashKey key1, const UHashKey key2); +uhash_compareCaselessUnicodeString(const UHashTok key1, const UHashTok key2); /** * Deleter function for UnicodeString* keys or values. @@ -490,13 +490,13 @@ uhash_deleteUnicodeString(void *obj); * Hash function for 32-bit integer keys. */ U_CAPI int32_t -uhash_hashLong(const UHashKey key); +uhash_hashLong(const UHashTok key); /** * Comparator function for 32-bit integer keys. */ U_CAPI UBool -uhash_compareLong(const UHashKey key1, const UHashKey key2); +uhash_compareLong(const UHashTok key1, const UHashTok key2); /******************************************************************** * Other Support Functions diff --git a/icu4c/source/common/uhash_us.cpp b/icu4c/source/common/uhash_us.cpp index ad547c59e9..951c5c382f 100644 --- a/icu4c/source/common/uhash_us.cpp +++ b/icu4c/source/common/uhash_us.cpp @@ -20,14 +20,14 @@ ********************************************************************/ U_CAPI int32_t -uhash_hashUnicodeString(const UHashKey key) { +uhash_hashUnicodeString(const UHashTok key) { U_NAMESPACE_USE const UnicodeString *str = (const UnicodeString*) key.pointer; return (str == NULL) ? 0 : str->hashCode(); } U_CAPI int32_t -uhash_hashCaselessUnicodeString(const UHashKey key) { +uhash_hashCaselessUnicodeString(const UHashTok key) { U_NAMESPACE_USE const UnicodeString *str = (const UnicodeString*) key.pointer; if (str == NULL) { @@ -46,7 +46,7 @@ uhash_deleteUnicodeString(void *obj) { } U_CAPI UBool -uhash_compareUnicodeString(const UHashKey key1, const UHashKey key2) { +uhash_compareUnicodeString(const UHashTok key1, const UHashTok key2) { U_NAMESPACE_USE const UnicodeString *str1 = (const UnicodeString*) key1.pointer; const UnicodeString *str2 = (const UnicodeString*) key2.pointer; @@ -60,7 +60,7 @@ uhash_compareUnicodeString(const UHashKey key1, const UHashKey key2) { } U_CAPI UBool -uhash_compareCaselessUnicodeString(const UHashKey key1, const UHashKey key2) { +uhash_compareCaselessUnicodeString(const UHashTok key1, const UHashTok key2) { U_NAMESPACE_USE const UnicodeString *str1 = (const UnicodeString*) key1.pointer; const UnicodeString *str2 = (const UnicodeString*) key2.pointer; diff --git a/icu4c/source/common/uresbund.c b/icu4c/source/common/uresbund.c index 4a544dccf5..c4fb24c76c 100644 --- a/icu4c/source/common/uresbund.c +++ b/icu4c/source/common/uresbund.c @@ -43,19 +43,19 @@ static UBool isMutexInited = FALSE; static UMTX resbMutex = NULL; /* INTERNAL: hashes an entry */ -static int32_t hashEntry(const UHashKey parm) { +static int32_t hashEntry(const UHashTok parm) { UResourceDataEntry *b = (UResourceDataEntry *)parm.pointer; - UHashKey namekey, pathkey; + UHashTok namekey, pathkey; namekey.pointer = b->fName; pathkey.pointer = b->fPath; return uhash_hashChars(namekey)+37*uhash_hashChars(pathkey); } /* INTERNAL: compares two entries */ -static UBool compareEntries(const UHashKey p1, const UHashKey p2) { +static UBool compareEntries(const UHashTok p1, const UHashTok p2) { UResourceDataEntry *b1 = (UResourceDataEntry *)p1.pointer; UResourceDataEntry *b2 = (UResourceDataEntry *)p2.pointer; - UHashKey name1, name2, path1, path2; + UHashTok name1, name2, path1, path2; name1.pointer = b1->fName; name2.pointer = b2->fName; path1.pointer = b1->fPath; @@ -182,7 +182,7 @@ static int32_t ures_flushCache() umtx_lock(&resbMutex); while ((e = uhash_nextElement(cache, &pos)) != NULL) { - resB = (UResourceDataEntry *) e->value; + resB = (UResourceDataEntry *) e->value.pointer; /* Deletes only if reference counter == 0 * Don't worry about the children of this node. * Those will eventually get deleted too, if not already. @@ -250,7 +250,7 @@ static UResourceDataEntry *init_entry(const char *localeID, const char *path, UE char aliasName[100] = { 0 }; int32_t aliasLen = 0; UBool isAlias = FALSE; - UHashKey hashkey; + UHashTok hashkey; if(U_FAILURE(*status)) { return NULL; diff --git a/icu4c/source/common/uvector.cpp b/icu4c/source/common/uvector.cpp index 5b3838fb1f..ff0e7253da 100644 --- a/icu4c/source/common/uvector.cpp +++ b/icu4c/source/common/uvector.cpp @@ -34,7 +34,7 @@ UVector::UVector(UObjectDeleter d, UKeyComparator c, UErrorCode &status, int32_t } void UVector::_init(int32_t initialCapacity, UErrorCode &status) { - elements = new UHashKey[initialCapacity]; + elements = new UHashTok[initialCapacity]; if (elements == 0) { status = U_MEMORY_ALLOCATION_ERROR; } else { @@ -129,7 +129,7 @@ void UVector::removeAllElements(void) { int32_t UVector::indexOf(void* obj, int32_t startIndex) const { if (comparer != 0) { - UHashKey key; + UHashTok key; key.pointer = obj; for (int32_t i=startIndex; inextElement(pos)) != 0) { UnicodeString* value = - new UnicodeString(*(const UnicodeString*)e->value); + new UnicodeString(*(const UnicodeString*)e->value.pointer); variableNames->put(*(UnicodeString*)e->key.pointer, value, status); } } diff --git a/icu4c/source/i18n/sortkey.cpp b/icu4c/source/i18n/sortkey.cpp index 62582ac016..402e440793 100644 --- a/icu4c/source/i18n/sortkey.cpp +++ b/icu4c/source/i18n/sortkey.cpp @@ -307,7 +307,7 @@ CollationKey::hashCode() const if (fHashCode == kInvalidHashCode) { - UHashKey key; + UHashTok key; key.pointer = fBytes; ((CollationKey *)this)->fHashCode = uhash_hashChars(key); #if 0 diff --git a/icu4c/source/i18n/ucol_elm.cpp b/icu4c/source/i18n/ucol_elm.cpp index 3982c3b949..69e12a075c 100644 --- a/icu4c/source/i18n/ucol_elm.cpp +++ b/icu4c/source/i18n/ucol_elm.cpp @@ -28,10 +28,10 @@ static uint32_t uprv_uca_processContraction(CntTable *contractions, UCAElements *element, uint32_t existingCE, UErrorCode *status); -static int32_t prefixLookupHash(const UHashKey e) { +static int32_t prefixLookupHash(const UHashTok e) { UCAElements *element = (UCAElements *)e.pointer; UChar buf[256]; - UHashKey key; + UHashTok key; key.pointer = buf; uprv_memcpy(buf, element->cPoints, element->cSize*sizeof(UChar)); buf[element->cSize] = 0; @@ -40,18 +40,18 @@ static int32_t prefixLookupHash(const UHashKey e) { return uhash_hashUChars(key); } -static int8_t prefixLookupComp(const UHashKey e1, const UHashKey e2) { +static int8_t prefixLookupComp(const UHashTok e1, const UHashTok e2) { UCAElements *element1 = (UCAElements *)e1.pointer; UCAElements *element2 = (UCAElements *)e2.pointer; UChar buf1[256]; - UHashKey key1; + UHashTok key1; key1.pointer = buf1; uprv_memcpy(buf1, element1->cPoints, element1->cSize*sizeof(UChar)); buf1[element1->cSize] = 0; UChar buf2[256]; - UHashKey key2; + UHashTok key2; key2.pointer = buf2; uprv_memcpy(buf2, element2->cPoints, element2->cSize*sizeof(UChar)); buf2[element2->cSize] = 0; @@ -545,7 +545,7 @@ static void uprv_uca_unsafeCPAddCCNZ(tempUCATable *t) { uint32_t NFCbufLen = 0; UErrorCode status = U_ZERO_ERROR; while((e = uhash_nextElement(t->prefixLookup, &i)) != NULL) { - element = (UCAElements *)e->value; + element = (UCAElements *)e->value.pointer; // codepoints here are in the NFD form. We need to add the // first code point of the NFC form to unsafe, because // strcoll needs to backup over them. diff --git a/icu4c/source/i18n/ucol_tok.cpp b/icu4c/source/i18n/ucol_tok.cpp index 929b138087..442854edb6 100644 --- a/icu4c/source/i18n/ucol_tok.cpp +++ b/icu4c/source/i18n/ucol_tok.cpp @@ -694,7 +694,7 @@ inline UColToken *getVirginBefore(UColTokenParser *src, UColToken *sourceToken, uint32_t key = (*newCharsLen << 24) | *charsOffset; - sourceToken = (UColToken *)uhash_geti(src->tailored, (int32_t)key); + sourceToken = (UColToken *)uhash_iget(src->tailored, (int32_t)key); return sourceToken; // if we found a tailored thing, we have to get one further down the line @@ -761,7 +761,7 @@ uint32_t ucol_tok_assembleTokenList(UColTokenParser *src, UParseError *parseErro key = newCharsLen << 24 | charsOffset; /* 4 Lookup each source in the CharsToToken map, and find a sourceToken */ - sourceToken = (UColToken *)uhash_geti(uchars2tokens, (int32_t)key); + sourceToken = (UColToken *)uhash_iget(uchars2tokens, (int32_t)key); if(newStrength != UCOL_TOK_RESET) { if(lastToken == NULL) { /* this means that rules haven't started properly */ @@ -785,7 +785,7 @@ uint32_t ucol_tok_assembleTokenList(UColTokenParser *src, UParseError *parseErro sourceToken->previous = NULL; sourceToken->noOfCEs = 0; sourceToken->noOfExpCEs = 0; - uhash_puti(uchars2tokens, (int32_t)sourceToken->source, sourceToken, status); + uhash_iput(uchars2tokens, (int32_t)sourceToken->source, sourceToken, status); } else { /* we could have fished out a reset here */ if(sourceToken->strength != UCOL_TOK_RESET && lastToken != sourceToken) { @@ -923,7 +923,7 @@ uint32_t ucol_tok_assembleTokenList(UColTokenParser *src, UParseError *parseErro while(searchCharsLen > 1 && sourceToken == NULL) { searchCharsLen--; key = searchCharsLen << 24 | charsOffset; - sourceToken = (UColToken *)uhash_geti(uchars2tokens, (int32_t)key); + sourceToken = (UColToken *)uhash_iget(uchars2tokens, (int32_t)key); } if(sourceToken != NULL) { expandNext = (newCharsLen - searchCharsLen) << 24 | (charsOffset + searchCharsLen); @@ -1046,7 +1046,7 @@ uint32_t ucol_tok_assembleTokenList(UColTokenParser *src, UParseError *parseErro ListList[src->resultLen].reset = sourceToken; src->resultLen++; - uhash_puti(uchars2tokens, (int32_t)sourceToken->source, sourceToken, status); + uhash_iput(uchars2tokens, (int32_t)sourceToken->source, sourceToken, status); } else { /* reset to something already in rules */ top = FALSE; } @@ -1081,7 +1081,7 @@ void ucol_tok_closeTokenList(UColTokenParser *src) { } int32_t -uhash_hashTokens(const UHashKey k) { +uhash_hashTokens(const UHashTok k) { int32_t hash = 0; uint32_t key = (uint32_t)k.integer; if (key != 0) { @@ -1099,7 +1099,7 @@ uhash_hashTokens(const UHashKey k) { return hash; } -UBool uhash_compareTokens(const UHashKey key1, const UHashKey key2) { +UBool uhash_compareTokens(const UHashTok key1, const UHashTok key2) { uint32_t p1 = (uint32_t) key1.integer; uint32_t p2 = (uint32_t) key2.integer; const UChar *s1 = (p1 & 0x00FFFFFF) + rulesToParse; diff --git a/icu4c/source/i18n/ucol_tok.h b/icu4c/source/i18n/ucol_tok.h index 190c828001..9a5bc0e588 100644 --- a/icu4c/source/i18n/ucol_tok.h +++ b/icu4c/source/i18n/ucol_tok.h @@ -134,8 +134,8 @@ U_CAPI const UChar U_EXPORT2 *ucol_tok_parseNextToken(UColTokenParser *src, UParseError *parseError, UErrorCode *status); -U_CFUNC int32_t uhash_hashTokens(const UHashKey k); -U_CFUNC UBool uhash_compareTokens(const UHashKey key1, const UHashKey key2); +U_CFUNC int32_t uhash_hashTokens(const UHashTok k); +U_CFUNC UBool uhash_compareTokens(const UHashTok key1, const UHashTok key2); U_CFUNC void deleteToken(void *token); #endif diff --git a/icu4c/source/test/cintltst/chashtst.c b/icu4c/source/test/cintltst/chashtst.c index 1ff9f07ace..ae13cddcc9 100644 --- a/icu4c/source/test/cintltst/chashtst.c +++ b/icu4c/source/test/cintltst/chashtst.c @@ -22,9 +22,9 @@ static void TestBasic(void); static void TestOtherAPI(void); -static int32_t hashChars(const UHashKey key); +static int32_t hashChars(const UHashTok key); -static UBool isEqualChars(const UHashKey key1, const UHashKey key2); +static UBool isEqualChars(const UHashTok key1, const UHashTok key2); static void _put(UHashtable* hash, const char* key, @@ -42,12 +42,12 @@ static void _remove(UHashtable* hash, void addHashtableTest(TestNode** root); /********************************************************************** - * UHashKey wrapper functions + * UHashTok wrapper functions *********************************************************************/ static UBool _compareChars(void* a, void* b) { - UHashKey s, t; + UHashTok s, t; s.pointer = a; t.pointer = b; return uhash_compareChars(s, t); @@ -55,7 +55,7 @@ _compareChars(void* a, void* b) { static UBool _compareIChars(void* a, void* b) { - UHashKey s, t; + UHashTok s, t; s.pointer = a; t.pointer = b; return uhash_compareIChars(s, t); @@ -63,7 +63,7 @@ _compareIChars(void* a, void* b) { static UBool _compareUChars(void* a, void* b) { - UHashKey s, t; + UHashTok s, t; s.pointer = a; t.pointer = b; return uhash_compareUChars(s, t); @@ -71,7 +71,7 @@ _compareUChars(void* a, void* b) { static UBool _compareLong(int32_t a, int32_t b) { - UHashKey s, t; + UHashTok s, t; s.integer = a; t.integer = b; return uhash_compareLong(s, t); @@ -227,9 +227,9 @@ static void TestOtherAPI(void){ uhash_setKeyComparator(hash, uhash_compareLong); uhash_setKeyHasher(hash, uhash_hashLong); - uhash_puti(hash, 1001, (void*)1, &status); - uhash_puti(hash, 1002, (void*)2, &status); - uhash_puti(hash, 1003, (void*)3, &status); + uhash_iput(hash, 1001, (void*)1, &status); + uhash_iput(hash, 1002, (void*)2, &status); + uhash_iput(hash, 1003, (void*)3, &status); if(_compareLong(1001, 1002) == TRUE || _compareLong(1001, 1001) != TRUE || _compareLong(1001, 0) == TRUE ) { @@ -238,16 +238,16 @@ static void TestOtherAPI(void){ /*set the resize policy to just GROW and SHRINK*/ /*how to test this??*/ uhash_setResizePolicy(hash, U_GROW_AND_SHRINK); - uhash_puti(hash, 1004, (void*)4, &status); - uhash_puti(hash, 1005, (void*)5, &status); - uhash_puti(hash, 1006, (void*)6, &status); + uhash_iput(hash, 1004, (void*)4, &status); + uhash_iput(hash, 1005, (void*)5, &status); + uhash_iput(hash, 1006, (void*)6, &status); if(uhash_count(hash) != 6){ log_err("FAIL: uhash_count() failed. Expected: 6, Got: %d\n", uhash_count(hash)); } - if((int32_t)uhash_removei(hash, 1004) != 4){ + if((int32_t)uhash_iremove(hash, 1004) != 4){ log_err("FAIL: uhash_remove failed\n"); } - if((int32_t)uhash_removei(hash, 1004) != 0){ + if((int32_t)uhash_iremove(hash, 1004) != 0){ log_err("FAIL: uhash_remove failed\n"); } uhash_close(hash); @@ -261,11 +261,11 @@ static void TestOtherAPI(void){ * This hash function is designed to collide a lot to test key equality * resolution. It only uses the first char. */ -static int32_t hashChars(const UHashKey key) { +static int32_t hashChars(const UHashTok key) { return *(const char*) key.pointer; } -static UBool isEqualChars(const UHashKey key1, const UHashKey key2) { +static UBool isEqualChars(const UHashTok key1, const UHashTok key2) { return (UBool)((key1.pointer != NULL) && (key2.pointer != NULL) && (uprv_strcmp((const char*)key1.pointer, (const char*)key2.pointer) == 0)); diff --git a/icu4c/source/test/intltest/sfwdchit.cpp b/icu4c/source/test/intltest/sfwdchit.cpp index 2cf9f3a51f..195e200db5 100644 --- a/icu4c/source/test/intltest/sfwdchit.cpp +++ b/icu4c/source/test/intltest/sfwdchit.cpp @@ -88,7 +88,7 @@ UBool SimpleFwdCharIterator::operator==(const ForwardCharacterIterator& that) co int32_t SimpleFwdCharIterator::hashCode(void) const { if (fHashCode == kInvalidHashCode) { - UHashKey key; + UHashTok key; key.pointer = fStart; ((SimpleFwdCharIterator *)this)->fHashCode = uhash_hashUChars(key); }