From: Markus Scherer Date: Mon, 4 Jul 2011 23:51:56 +0000 (+0000) Subject: ICU-8617 move UHashTok into lower-level uelement.h (new) and rename to UElement to... X-Git-Tag: milestone-59-0-1~4686 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=744d1f3a19e25bdb1b1f04b73419c168f66351a0;p=icu ICU-8617 move UHashTok into lower-level uelement.h (new) and rename to UElement to share with UVector X-SVN-Rev: 30272 --- diff --git a/icu4c/source/common/common.vcxproj b/icu4c/source/common/common.vcxproj index fc22849a95b..5c8edc9b6e8 100644 --- a/icu4c/source/common/common.vcxproj +++ b/icu4c/source/common/common.vcxproj @@ -569,6 +569,7 @@ ..\..\include\unicode\%(Filename)%(Extension);%(Outputs) + diff --git a/icu4c/source/common/common.vcxproj.filters b/icu4c/source/common/common.vcxproj.filters index fa30c48de2a..26f1c694516 100644 --- a/icu4c/source/common/common.vcxproj.filters +++ b/icu4c/source/common/common.vcxproj.filters @@ -582,6 +582,9 @@ collections + + collections + collections diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index 3a8690812c0..c5e4dc42a13 100644 --- a/icu4c/source/common/locid.cpp +++ b/icu4c/source/common/locid.cpp @@ -38,6 +38,7 @@ #include "cstring.h" #include "uhash.h" #include "ucln_cmn.h" +#include "ustr_imp.h" #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) @@ -635,9 +636,7 @@ Locale& Locale::init(const char* localeID, UBool canonicalize) int32_t Locale::hashCode() const { - UHashTok hashKey; - hashKey.pointer = fullName; - return uhash_hashChars(hashKey); + return ustr_hashCharsN(fullName, uprv_strlen(fullName)); } void diff --git a/icu4c/source/common/uelement.h b/icu4c/source/common/uelement.h new file mode 100644 index 00000000000..c5177754990 --- /dev/null +++ b/icu4c/source/common/uelement.h @@ -0,0 +1,85 @@ +/* +******************************************************************************* +* Copyright (C) 1997-2011, International Business Machines +* Corporation and others. All Rights Reserved. +******************************************************************************* +* file name: uelement.h +* encoding: US-ASCII +* tab size: 8 (not used) +* indentation:4 +* +* created on: 2011jul04 +* created by: Markus W. Scherer +* +* Common definitions for UHashTable and UVector. +* UHashTok moved here from uhash.h and renamed UElement. +* This allows users of UVector to avoid the confusing #include of uhash.h. +* uhash.h aliases UElement to UHashTok, +* so that we need not change all of its code and its users. +*/ + +#ifndef __UELEMENT_H__ +#define __UELEMENT_H__ + +#include "unicode/utypes.h" + +/** + * A UVector element, or a key or value within a UHashtable. + * 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). + * + * Because a UElement is the size of a native pointer or a 32-bit + * integer, we pass it around by value. + */ +union UElement { + void* pointer; + int32_t integer; +}; +typedef union UElement UElement; + +/** + * An element-equality (boolean) comparison function. + * @param e1 An element (object or integer) + * @param e2 An element (object or integer) + * @return TRUE if the two elements are equal. + */ +typedef UBool U_CALLCONV UElementsAreEqual(const UElement e1, const UElement e2); + +/** + * An element sorting (three-way) comparison function. + * @param e1 An element (object or integer) + * @param e2 An element (object or integer) + * @return 0 if the two elements are equal, -1 if e1 is < e2, or +1 if e1 is > e2. + */ +typedef int8_t U_CALLCONV UElementComparator(UElement e1, UElement e2); + +/** + * An element assignment function. It may copy an integer, copy + * a pointer, or clone a pointer, as appropriate. + * @param dst The element to be assigned to + * @param src The element to assign from + */ +typedef void U_CALLCONV UElementAssigner(UElement *dst, UElement *src); + +/** + * Comparator function for UnicodeString* keys. Implements UElementsAreEqual. + * @param key1 The string for comparison + * @param key2 The string for comparison + * @return true if key1 and key2 are equal, return false otherwise. + */ +U_CAPI UBool U_EXPORT2 +uhash_compareUnicodeString(const UElement key1, const UElement key2); + +/** + * Comparator function for UnicodeString* keys (case insensitive). + * Make sure to use together with uhash_hashCaselessUnicodeString. + * Implements UElementsAreEqual. + * @param key1 The string for comparison + * @param key2 The string for comparison + * @return true if key1 and key2 are equal, return false otherwise. + */ +U_CAPI UBool U_EXPORT2 +uhash_compareCaselessUnicodeString(const UElement key1, const UElement key2); + +#endif /* __UELEMENT_H__ */ diff --git a/icu4c/source/common/uhash.h b/icu4c/source/common/uhash.h index bf3275c5901..ec4c630dc7d 100644 --- a/icu4c/source/common/uhash.h +++ b/icu4c/source/common/uhash.h @@ -15,6 +15,7 @@ #include "unicode/utypes.h" #include "cmemory.h" +#include "uelement.h" /** * UHashtable stores key-value pairs and does moderately fast lookup @@ -77,20 +78,11 @@ U_CDECL_BEGIN /** - * 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 + * A key or value within a UHashtable. + * The hashing and comparison functions take a pointer to a * UHashTok, but the deleter receives the void* pointer within it. - * - * Because a UHashTok is the size of a native pointer or a 32-bit - * integer, we pass it around by value. */ -union UHashTok { - void* pointer; - int32_t integer; -}; -typedef union UHashTok UHashTok; +typedef UElement UHashTok; /** * This is a single hash element. @@ -111,21 +103,14 @@ typedef struct UHashElement UHashElement; typedef int32_t U_CALLCONV UHashFunction(const UHashTok key); /** - * A key comparison function. - * @param key1 A key stored in a hashtable - * @param key2 A key stored in a hashtable - * @return TRUE if the two keys are equal. + * A key equality (boolean) comparison function. */ -typedef UBool U_CALLCONV UKeyComparator(const UHashTok key1, - const UHashTok key2); +typedef UElementsAreEqual UKeyComparator; + /** - * A key comparison function. - * @param val1 A key stored in a hashtable - * @param val2 A key stored in a hashtable - * @return TRUE if the two keys are equal. + * A value equality (boolean) comparison function. */ -typedef UBool U_CALLCONV UValueComparator(const UHashTok val1, - const UHashTok val2); +typedef UElementsAreEqual UValueComparator; /* see cmemory.h for UObjectDeleter and uprv_deleteUObject() */ @@ -624,7 +609,7 @@ uhash_compareIChars(const UHashTok key1, const UHashTok key2); * @return A hash code for the key. */ U_CAPI int32_t U_EXPORT2 -uhash_hashUnicodeString(const UHashTok key); +uhash_hashUnicodeString(const UElement key); /** * Hash function for UnicodeString* keys (case insensitive). @@ -633,26 +618,7 @@ uhash_hashUnicodeString(const UHashTok key); * @return A hash code for the key. */ U_CAPI int32_t U_EXPORT2 -uhash_hashCaselessUnicodeString(const UHashTok key); - -/** - * Comparator function for UnicodeString* keys. - * @param key1 The string for comparison - * @param key2 The string for comparison - * @return true if key1 and key2 are equal, return false otherwise. - */ -U_CAPI UBool U_EXPORT2 -uhash_compareUnicodeString(const UHashTok key1, const UHashTok key2); - -/** - * Comparator function for UnicodeString* keys (case insensitive). - * Make sure to use together with uhash_hashCaselessUnicodeString. - * @param key1 The string for comparison - * @param key2 The string for comparison - * @return true if key1 and key2 are equal, return false otherwise. - */ -U_CAPI UBool U_EXPORT2 -uhash_compareCaselessUnicodeString(const UHashTok key1, const UHashTok key2); +uhash_hashCaselessUnicodeString(const UElement key); /******************************************************************** * int32_t Support Functions diff --git a/icu4c/source/common/uniset.cpp b/icu4c/source/common/uniset.cpp index 9ff9ae58f2a..bc204bfef66 100644 --- a/icu4c/source/common/uniset.cpp +++ b/icu4c/source/common/uniset.cpp @@ -16,13 +16,12 @@ #include "cmemory.h" #include "cstring.h" #include "patternprops.h" -#include "uhash.h" +#include "uelement.h" #include "util.h" #include "uvector.h" #include "charstr.h" #include "ustrfmt.h" #include "uassert.h" -#include "hash.h" #include "bmpset.h" #include "unisetspan.h" @@ -124,11 +123,11 @@ static inline void _dbgdt(UnicodeSet* set) { // UnicodeString in UVector support //---------------------------------------------------------------- -static void U_CALLCONV cloneUnicodeString(UHashTok *dst, UHashTok *src) { +static void U_CALLCONV cloneUnicodeString(UElement *dst, UElement *src) { dst->pointer = new UnicodeString(*(UnicodeString*)src->pointer); } -static int8_t U_CALLCONV compareUnicodeString(UHashTok t1, UHashTok t2) { +static int8_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) { const UnicodeString &a = *(const UnicodeString*)t1.pointer; const UnicodeString &b = *(const UnicodeString*)t2.pointer; return a.compare(b); diff --git a/icu4c/source/common/unistr.cpp b/icu4c/source/common/unistr.cpp index f181cd3f018..3df71d75415 100644 --- a/icu4c/source/common/unistr.cpp +++ b/icu4c/source/common/unistr.cpp @@ -25,7 +25,7 @@ #include "cmemory.h" #include "unicode/ustring.h" #include "unicode/unistr.h" -#include "uhash.h" +#include "uelement.h" #include "ustr_imp.h" #include "umutex.h" @@ -1677,7 +1677,7 @@ U_NAMESPACE_END U_NAMESPACE_USE U_CAPI int32_t U_EXPORT2 -uhash_hashUnicodeString(const UHashTok key) { +uhash_hashUnicodeString(const UElement key) { const UnicodeString *str = (const UnicodeString*) key.pointer; return (str == NULL) ? 0 : str->hashCode(); } @@ -1685,7 +1685,7 @@ uhash_hashUnicodeString(const UHashTok key) { // Moved here from uhash_us.cpp so that using a UVector of UnicodeString* // does not depend on hashtable code. U_CAPI UBool U_EXPORT2 -uhash_compareUnicodeString(const UHashTok key1, const UHashTok key2) { +uhash_compareUnicodeString(const UElement key1, const UElement key2) { const UnicodeString *str1 = (const UnicodeString*) key1.pointer; const UnicodeString *str2 = (const UnicodeString*) key2.pointer; if (str1 == str2) { diff --git a/icu4c/source/common/unistr_case.cpp b/icu4c/source/common/unistr_case.cpp index 4dda68a1813..bab50d4ffbc 100644 --- a/icu4c/source/common/unistr_case.cpp +++ b/icu4c/source/common/unistr_case.cpp @@ -23,8 +23,8 @@ #include "unicode/ustring.h" #include "unicode/unistr.h" #include "unicode/uchar.h" +#include "uelement.h" #include "ustr_imp.h" -#include "uhash.h" U_NAMESPACE_BEGIN @@ -150,7 +150,7 @@ U_NAMESPACE_END // Defined here to reduce dependencies on break iterator U_CAPI int32_t U_EXPORT2 -uhash_hashCaselessUnicodeString(const UHashTok key) { +uhash_hashCaselessUnicodeString(const UElement key) { U_NAMESPACE_USE const UnicodeString *str = (const UnicodeString*) key.pointer; if (str == NULL) { @@ -164,7 +164,7 @@ uhash_hashCaselessUnicodeString(const UHashTok key) { // Defined here to reduce dependencies on break iterator U_CAPI UBool U_EXPORT2 -uhash_compareCaselessUnicodeString(const UHashTok key1, const UHashTok key2) { +uhash_compareCaselessUnicodeString(const UElement key1, const UElement key2) { U_NAMESPACE_USE const UnicodeString *str1 = (const UnicodeString*) key1.pointer; const UnicodeString *str2 = (const UnicodeString*) key2.pointer; diff --git a/icu4c/source/common/ustack.cpp b/icu4c/source/common/ustack.cpp index 76118bce99a..c58de7ba1f5 100644 --- a/icu4c/source/common/ustack.cpp +++ b/icu4c/source/common/ustack.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (C) 2003-2004, International Business Machines +* Copyright (C) 2003-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ @@ -21,12 +21,12 @@ UStack::UStack(int32_t initialCapacity, UErrorCode &status) : { } -UStack::UStack(UObjectDeleter *d, UKeyComparator *c, UErrorCode &status) : +UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status) : UVector(d, c, status) { } -UStack::UStack(UObjectDeleter *d, UKeyComparator *c, int32_t initialCapacity, UErrorCode &status) : +UStack::UStack(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status) : UVector(d, c, initialCapacity, status) { } diff --git a/icu4c/source/common/uvector.cpp b/icu4c/source/common/uvector.cpp index 2a566ed21f6..a5adaa058ee 100644 --- a/icu4c/source/common/uvector.cpp +++ b/icu4c/source/common/uvector.cpp @@ -11,6 +11,7 @@ #include "uvector.h" #include "cmemory.h" #include "uarrsort.h" +#include "uelement.h" U_NAMESPACE_BEGIN @@ -46,7 +47,7 @@ UVector::UVector(int32_t initialCapacity, UErrorCode &status) : _init(initialCapacity, status); } -UVector::UVector(UObjectDeleter *d, UKeyComparator *c, UErrorCode &status) : +UVector::UVector(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status) : count(0), capacity(0), elements(0), @@ -56,7 +57,7 @@ UVector::UVector(UObjectDeleter *d, UKeyComparator *c, UErrorCode &status) : _init(DEFAULT_CAPACITY, status); } -UVector::UVector(UObjectDeleter *d, UKeyComparator *c, int32_t initialCapacity, UErrorCode &status) : +UVector::UVector(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status) : count(0), capacity(0), elements(0), @@ -71,10 +72,10 @@ void UVector::_init(int32_t initialCapacity, UErrorCode &status) { return; } // Fix bogus initialCapacity values; avoid malloc(0) and integer overflow - if ((initialCapacity < 1) || (initialCapacity > (int32_t)(INT32_MAX / sizeof(UHashTok)))) { + if ((initialCapacity < 1) || (initialCapacity > (int32_t)(INT32_MAX / sizeof(UElement)))) { initialCapacity = DEFAULT_CAPACITY; } - elements = (UHashTok *)uprv_malloc(sizeof(UHashTok)*initialCapacity); + elements = (UElement *)uprv_malloc(sizeof(UElement)*initialCapacity); if (elements == 0) { status = U_MEMORY_ALLOCATION_ERROR; } else { @@ -92,7 +93,7 @@ UVector::~UVector() { * Assign this object to another (make this a copy of 'other'). * Use the 'assign' function to assign each element. */ -void UVector::assign(const UVector& other, UTokenAssigner *assign, UErrorCode &ec) { +void UVector::assign(const UVector& other, UElementAssigner *assign, UErrorCode &ec) { if (ensureCapacity(other.count, ec)) { setSize(other.count, ec); if (U_SUCCESS(ec)) { @@ -272,7 +273,7 @@ UBool UVector::equals(const UVector &other) const { } } } else { - UHashTok key; + UElement key; for (i=0; i (int32_t)(INT32_MAX / sizeof(UHashTok))) { // integer overflow check + if (newCap > (int32_t)(INT32_MAX / sizeof(UElement))) { // integer overflow check // We keep the original memory contents on bad minimumCapacity. status = U_ILLEGAL_ARGUMENT_ERROR; return FALSE; } - UHashTok* newElems = (UHashTok *)uprv_realloc(elements, sizeof(UHashTok)*newCap); + UElement* newElems = (UElement *)uprv_realloc(elements, sizeof(UElement)*newCap); if (newElems == NULL) { // We keep the original contents on the memory failure on realloc or bad minimumCapacity. status = U_MEMORY_ALLOCATION_ERROR; @@ -371,7 +372,7 @@ void UVector::setSize(int32_t newSize, UErrorCode &status) { if (!ensureCapacity(newSize, status)) { return; } - UHashTok empty; + UElement empty; empty.pointer = NULL; empty.integer = 0; for (i=count; i 0) { max = probe; } else { @@ -475,7 +476,7 @@ void UVector::sortedInsert(UHashTok tok, USortComparator *compare, UErrorCode& e for (int32_t i=count; i>min; --i) { elements[i] = elements[i-1]; } - elements[min] = tok; + elements[min] = e; ++count; } } @@ -493,10 +494,10 @@ void UVector::sortedInsert(UHashTok tok, USortComparator *compare, UErrorCode& e */ static int32_t U_CALLCONV sortComparator(const void *context, const void *left, const void *right) { - USortComparator *compare = *static_cast(context); - UHashTok tok1 = *static_cast(left); - UHashTok tok2 = *static_cast(right); - int32_t result = (*compare)(tok1, tok2); + UElementComparator *compare = *static_cast(context); + UElement e1 = *static_cast(left); + UElement e2 = *static_cast(right); + int32_t result = (*compare)(e1, e2); return result; } @@ -507,22 +508,22 @@ sortComparator(const void *context, const void *left, const void *right) { */ static int32_t U_CALLCONV sortiComparator(const void * /*context */, const void *left, const void *right) { - const UHashTok *tok1 = static_cast(left); - const UHashTok *tok2 = static_cast(right); - int32_t result = tok1->integer < tok2->integer? -1 : - tok1->integer == tok2->integer? 0 : 1; + const UElement *e1 = static_cast(left); + const UElement *e2 = static_cast(right); + int32_t result = e1->integer < e2->integer? -1 : + e1->integer == e2->integer? 0 : 1; return result; } /** * Sort the vector, assuming it constains ints. * (A more general sort would take a comparison function, but it's - * not clear whether UVector's USortComparator or + * not clear whether UVector's UElementComparator or * UComparator from uprv_sortAray would be more appropriate.) */ void UVector::sorti(UErrorCode &ec) { if (U_SUCCESS(ec)) { - uprv_sortArray(elements, count, sizeof(UHashTok), + uprv_sortArray(elements, count, sizeof(UElement), sortiComparator, NULL, FALSE, &ec); } } @@ -542,9 +543,9 @@ void UVector::sorti(UErrorCode &ec) { * as a (void *) data pointer, so instead we pass a (data) pointer to a * pointer-to-function variable. */ -void UVector::sort(USortComparator *compare, UErrorCode &ec) { +void UVector::sort(UElementComparator *compare, UErrorCode &ec) { if (U_SUCCESS(ec)) { - uprv_sortArray(elements, count, sizeof(UHashTok), + uprv_sortArray(elements, count, sizeof(UElement), sortComparator, &compare, FALSE, &ec); } } @@ -555,7 +556,7 @@ void UVector::sort(USortComparator *compare, UErrorCode &ec) { */ void UVector::sortWithUComparator(UComparator *compare, const void *context, UErrorCode &ec) { if (U_SUCCESS(ec)) { - uprv_sortArray(elements, count, sizeof(UHashTok), + uprv_sortArray(elements, count, sizeof(UElement), compare, context, FALSE, &ec); } } diff --git a/icu4c/source/common/uvector.h b/icu4c/source/common/uvector.h index c28ddd317c6..a04176266f4 100644 --- a/icu4c/source/common/uvector.h +++ b/icu4c/source/common/uvector.h @@ -14,30 +14,12 @@ #include "unicode/utypes.h" #include "unicode/uobject.h" +#include "cmemory.h" #include "uarrsort.h" -#include "uhash.h" +#include "uelement.h" U_NAMESPACE_BEGIN -/** - * A token comparison function. - * @param tok1 A token (object or integer) - * @param tok2 A token (object or integer) - * @return 0 if the two tokens are equal, -1 if tok1 is < tok2, or - * +1 if tok1 is > tok2. - */ -typedef int8_t U_CALLCONV USortComparator(UHashTok tok1, - UHashTok tok2); - -/** - * A token assignment function. It may copy an integer, copy - * a pointer, or clone a pointer, as appropriate. - * @param dst The token to be assigned to - * @param src The token to assign from - */ -typedef void U_CALLCONV UTokenAssigner(UHashTok *dst, - UHashTok *src); - /** *

Ultralightweight C++ implementation of a void* vector * that is (mostly) compatible with java.util.Vector. @@ -90,7 +72,7 @@ typedef void U_CALLCONV UTokenAssigner(UHashTok *dst, */ class U_COMMON_API UVector : public UObject { // NOTE: UVector uses the UHashKey (union of void* and int32_t) as - // its basic storage type. It uses UKeyComparator as its + // its basic storage type. It uses UElementsAreEqual as its // comparison function. It uses UObjectDeleter as its deleter // function. These are named for hashtables, but used here as-is // rather than duplicating the type. This allows sharing of @@ -101,20 +83,20 @@ private: int32_t capacity; - UHashTok* elements; + UElement* elements; UObjectDeleter *deleter; - UKeyComparator *comparer; + UElementsAreEqual *comparer; public: UVector(UErrorCode &status); UVector(int32_t initialCapacity, UErrorCode &status); - UVector(UObjectDeleter *d, UKeyComparator *c, UErrorCode &status); + UVector(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status); - UVector(UObjectDeleter *d, UKeyComparator *c, int32_t initialCapacity, UErrorCode &status); + UVector(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status); virtual ~UVector(); @@ -122,7 +104,7 @@ public: * Assign this object to another (make this a copy of 'other'). * Use the 'assign' function to assign each element. */ - void assign(const UVector& other, UTokenAssigner *assign, UErrorCode &ec); + void assign(const UVector& other, UElementAssigner *assign, UErrorCode &ec); /** * Compare this vector with another. They will be considered @@ -209,7 +191,7 @@ public: UObjectDeleter *setDeleter(UObjectDeleter *d); - UKeyComparator *setComparer(UKeyComparator *c); + UElementsAreEqual *setComparer(UElementsAreEqual *c); void* operator[](int32_t index) const; @@ -237,14 +219,14 @@ public: * as defined by 'compare'. The current elements are assumed to * be sorted already. */ - void sortedInsert(void* obj, USortComparator *compare, UErrorCode& ec); + void sortedInsert(void* obj, UElementComparator *compare, UErrorCode& ec); /** * Insert the given integer into this vector at its sorted position * as defined by 'compare'. The current elements are assumed to * be sorted already. */ - void sortedInsert(int32_t obj, USortComparator *compare, UErrorCode& ec); + void sortedInsert(int32_t obj, UElementComparator *compare, UErrorCode& ec); /** * Sort the contents of the vector, assuming that the contents of the @@ -255,10 +237,10 @@ public: /** * Sort the contents of this vector, using a caller-supplied function * to do the comparisons. (It's confusing that - * UVector's USortComparator function is different from the + * UVector's UElementComparator function is different from the * UComparator function type defined in uarrsort.h) */ - void sort(USortComparator *compare, UErrorCode &ec); + void sort(UElementComparator *compare, UErrorCode &ec); /** * Sort the contents of this vector using a caller-supplied function @@ -281,9 +263,9 @@ public: private: void _init(int32_t initialCapacity, UErrorCode &status); - int32_t indexOf(UHashTok key, int32_t startIndex = 0, int8_t hint = 0) const; + int32_t indexOf(UElement key, int32_t startIndex = 0, int8_t hint = 0) const; - void sortedInsert(UHashTok tok, USortComparator *compare, UErrorCode& ec); + void sortedInsert(UElement e, UElementComparator *compare, UErrorCode& ec); // Disallow UVector(const UVector&); @@ -316,9 +298,9 @@ public: UStack(int32_t initialCapacity, UErrorCode &status); - UStack(UObjectDeleter *d, UKeyComparator *c, UErrorCode &status); + UStack(UObjectDeleter *d, UElementsAreEqual *c, UErrorCode &status); - UStack(UObjectDeleter *d, UKeyComparator *c, int32_t initialCapacity, UErrorCode &status); + UStack(UObjectDeleter *d, UElementsAreEqual *c, int32_t initialCapacity, UErrorCode &status); virtual ~UStack(); diff --git a/icu4c/source/i18n/alphaindex.cpp b/icu4c/source/i18n/alphaindex.cpp index a4bb522a69b..2247a45ff44 100644 --- a/icu4c/source/i18n/alphaindex.cpp +++ b/icu4c/source/i18n/alphaindex.cpp @@ -724,10 +724,10 @@ void AlphabeticIndex::staticInit(UErrorCode &status) { // static int32_t U_CALLCONV sortCollateComparator(const void *context, const void *left, const void *right) { - const UHashTok *leftTok = static_cast(left); - const UHashTok *rightTok = static_cast(right); - const UnicodeString *leftString = static_cast(leftTok->pointer); - const UnicodeString *rightString = static_cast(rightTok->pointer); + const UElement *leftElement = static_cast(left); + const UElement *rightElement = static_cast(right); + const UnicodeString *leftString = static_cast(leftElement->pointer); + const UnicodeString *rightString = static_cast(rightElement->pointer); const Collator *col = static_cast(context); if (leftString == rightString) { @@ -749,10 +749,10 @@ sortCollateComparator(const void *context, const void *left, const void *right) // static int32_t U_CALLCONV recordCompareFn(const void *context, const void *left, const void *right) { - const UHashTok *leftTok = static_cast(left); - const UHashTok *rightTok = static_cast(right); - const AlphabeticIndex::Record *leftRec = static_cast(leftTok->pointer); - const AlphabeticIndex::Record *rightRec = static_cast(rightTok->pointer); + const UElement *leftElement = static_cast(left); + const UElement *rightElement = static_cast(right); + const AlphabeticIndex::Record *leftRec = static_cast(leftElement->pointer); + const AlphabeticIndex::Record *rightRec = static_cast(rightElement->pointer); const Collator *col = static_cast(context); Collator::EComparisonResult r = col->compare(leftRec->sortingName_, rightRec->sortingName_); @@ -1070,16 +1070,16 @@ void AlphabeticIndex::hackName(UnicodeString &dest, const UnicodeString &name, c * * For use with array sort or UVector. * @param context A UErrorCode pointer. - * @param left A UHashTok pointer, which must refer to a UnicodeString * - * @param right A UHashTok pointer, which must refer to a UnicodeString * + * @param left A UElement pointer, which must refer to a UnicodeString * + * @param right A UElement pointer, which must refer to a UnicodeString * */ static int32_t U_CALLCONV PreferenceComparator(const void *context, const void *left, const void *right) { - const UHashTok *leftTok = static_cast(left); - const UHashTok *rightTok = static_cast(right); - const UnicodeString *s1 = static_cast(leftTok->pointer); - const UnicodeString *s2 = static_cast(rightTok->pointer); + const UElement *leftElement = static_cast(left); + const UElement *rightElement = static_cast(right); + const UnicodeString *s1 = static_cast(leftElement->pointer); + const UnicodeString *s2 = static_cast(rightElement->pointer); UErrorCode &status = *(UErrorCode *)(context); // Cast off both static and const. if (s1 == s2) { return 0; diff --git a/icu4c/source/i18n/msgfmt.cpp b/icu4c/source/i18n/msgfmt.cpp index 212a809cdd8..b3c6b566221 100644 --- a/icu4c/source/i18n/msgfmt.cpp +++ b/icu4c/source/i18n/msgfmt.cpp @@ -40,6 +40,8 @@ #include "messageimpl.h" #include "msgfmt_impl.h" #include "uassert.h" +#include "uelement.h" +#include "uhash.h" #include "ustrfmt.h" #include "util.h" #include "uvector.h" diff --git a/icu4c/source/i18n/sortkey.cpp b/icu4c/source/i18n/sortkey.cpp index bb4ee8192d2..5c01a10cd31 100644 --- a/icu4c/source/i18n/sortkey.cpp +++ b/icu4c/source/i18n/sortkey.cpp @@ -33,7 +33,8 @@ #include "unicode/sortkey.h" #include "cmemory.h" -#include "uhash.h" +#include "uelement.h" +#include "ustr_imp.h" U_NAMESPACE_BEGIN @@ -361,9 +362,8 @@ CollationKey::hashCode() const if (fHashCode == kInvalidHashCode) { - UHashTok key; - key.pointer = fBytes; - ((CollationKey *)this)->fHashCode = uhash_hashChars(key); + const char *s = reinterpret_cast(fBytes); + ((CollationKey *)this)->fHashCode = s == NULL ? 0 : ustr_hashCharsN(s, fCount); #if 0 // We compute the hash by iterating sparsely over 64 (at most) characters // spaced evenly through the string. For each character, we multiply the diff --git a/icu4c/source/i18n/unicode/currpinf.h b/icu4c/source/i18n/unicode/currpinf.h index 0f6781012d7..9ade99a09e5 100644 --- a/icu4c/source/i18n/unicode/currpinf.h +++ b/icu4c/source/i18n/unicode/currpinf.h @@ -18,8 +18,6 @@ #include "unicode/unistr.h" -union UHashTok; - U_NAMESPACE_BEGIN class Locale; diff --git a/icu4c/source/i18n/unicode/decimfmt.h b/icu4c/source/i18n/unicode/decimfmt.h index 048ee858aac..fa167a6a017 100644 --- a/icu4c/source/i18n/unicode/decimfmt.h +++ b/icu4c/source/i18n/unicode/decimfmt.h @@ -38,8 +38,6 @@ #include "unicode/fpositer.h" #include "unicode/stringpiece.h" -union UHashTok; - U_NAMESPACE_BEGIN class DigitList; diff --git a/icu4c/source/i18n/unicode/dtitvinf.h b/icu4c/source/i18n/unicode/dtitvinf.h index f6513a2147b..14418c66f15 100644 --- a/icu4c/source/i18n/unicode/dtitvinf.h +++ b/icu4c/source/i18n/unicode/dtitvinf.h @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2008-2010, International Business Machines Corporation and + * Copyright (C) 2008-2011, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* * @@ -25,14 +25,6 @@ #include "unicode/locid.h" #include "unicode/ucal.h" #include "unicode/dtptngen.h" -//#include "dtitv_impl.h" - -/** - * @internal ICU 4.0 - */ - -union UHashTok; - U_NAMESPACE_BEGIN diff --git a/icu4c/source/i18n/unicode/tmutfmt.h b/icu4c/source/i18n/unicode/tmutfmt.h index 35f5dc6c6c2..8252cc205b8 100644 --- a/icu4c/source/i18n/unicode/tmutfmt.h +++ b/icu4c/source/i18n/unicode/tmutfmt.h @@ -25,12 +25,6 @@ #include "unicode/numfmt.h" #include "unicode/plurrule.h" -/** - * @internal ICU 4.2 - */ - -union UHashTok; - /** * Constants for various styles. * There are 2 styles: full name and abbreviated name. diff --git a/icu4c/source/test/intltest/uvectest.cpp b/icu4c/source/test/intltest/uvectest.cpp index 98b2f38c021..43841e958ce 100644 --- a/icu4c/source/test/intltest/uvectest.cpp +++ b/icu4c/source/test/intltest/uvectest.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2004-2010, International Business Machines Corporation and + * Copyright (c) 2004-2011, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -9,10 +9,10 @@ #include "intltest.h" #include "uvectest.h" -#include "uvector.h" -#include "hash.h" - #include "cstring.h" +#include "hash.h" +#include "uelement.h" +#include "uvector.h" //--------------------------------------------------------------------------- // @@ -67,7 +67,7 @@ void UVectorTest::runIndexedTest( int32_t index, UBool exec, const char* &name, } static int8_t U_CALLCONV -UVectorTest_compareInt32(UHashTok key1, UHashTok key2) { +UVectorTest_compareInt32(UElement key1, UElement key2) { if (key1.integer > key2.integer) { return 1; } @@ -79,7 +79,7 @@ UVectorTest_compareInt32(UHashTok key1, UHashTok key2) { U_CDECL_BEGIN static int8_t U_CALLCONV -UVectorTest_compareCstrings(const UHashTok key1, const UHashTok key2) { +UVectorTest_compareCstrings(const UElement key1, const UElement key2) { return !strcmp((const char *)key1.pointer, (const char *)key2.pointer); } U_CDECL_END @@ -161,7 +161,7 @@ void UVectorTest::UStack_API() { } U_CDECL_BEGIN -static UBool U_CALLCONV neverTRUE(const UHashTok /*key1*/, const UHashTok /*key2*/) { +static UBool U_CALLCONV neverTRUE(const UElement /*key1*/, const UElement /*key2*/) { return FALSE; } diff --git a/icu4c/source/tools/genrb/reslist.c b/icu4c/source/tools/genrb/reslist.c index a57ed5aa71d..0f0130a2cf5 100644 --- a/icu4c/source/tools/genrb/reslist.c +++ b/icu4c/source/tools/genrb/reslist.c @@ -24,6 +24,7 @@ #include "errmsg.h" #include "uarrsort.h" +#include "uelement.h" #include "uinvchar.h" #include "ustr_imp.h" @@ -885,13 +886,13 @@ struct SResource* array_open(struct SRBRoot *bundle, const char *tag, const stru } static int32_t U_CALLCONV -string_hash(const UHashTok key) { +string_hash(const UElement key) { const struct SResource *res = (struct SResource *)key.pointer; return ustr_hashUCharsN(res->u.fString.fChars, res->u.fString.fLength); } static UBool U_CALLCONV -string_comp(const UHashTok key1, const UHashTok key2) { +string_comp(const UElement key1, const UElement key2) { const struct SResource *res1 = (struct SResource *)key1.pointer; const struct SResource *res2 = (struct SResource *)key2.pointer; return 0 == u_strCompare(res1->u.fString.fChars, res1->u.fString.fLength,