]> granicus.if.org Git - icu/commitdiff
ICU-8617 move UHashTok into lower-level uelement.h (new) and rename to UElement to...
authorMarkus Scherer <markus.icu@gmail.com>
Mon, 4 Jul 2011 23:51:56 +0000 (23:51 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Mon, 4 Jul 2011 23:51:56 +0000 (23:51 +0000)
X-SVN-Rev: 30272

20 files changed:
icu4c/source/common/common.vcxproj
icu4c/source/common/common.vcxproj.filters
icu4c/source/common/locid.cpp
icu4c/source/common/uelement.h [new file with mode: 0644]
icu4c/source/common/uhash.h
icu4c/source/common/uniset.cpp
icu4c/source/common/unistr.cpp
icu4c/source/common/unistr_case.cpp
icu4c/source/common/ustack.cpp
icu4c/source/common/uvector.cpp
icu4c/source/common/uvector.h
icu4c/source/i18n/alphaindex.cpp
icu4c/source/i18n/msgfmt.cpp
icu4c/source/i18n/sortkey.cpp
icu4c/source/i18n/unicode/currpinf.h
icu4c/source/i18n/unicode/decimfmt.h
icu4c/source/i18n/unicode/dtitvinf.h
icu4c/source/i18n/unicode/tmutfmt.h
icu4c/source/test/intltest/uvectest.cpp
icu4c/source/tools/genrb/reslist.c

index fc22849a95bc2236ac40774996da3846e136ce7b..5c8edc9b6e8c0e1b2caf94222aa5a9e5593dae60 100644 (file)
 </Command>\r
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>\r
     </CustomBuild>\r
+    <ClInclude Include="uelement.h" />\r
     <ClInclude Include="uenumimp.h" />\r
     <ClInclude Include="uhash.h" />\r
     <ClInclude Include="ulist.h" />\r
index fa30c48de2aac6be438cf9b7c01027c92e574279..26f1c6945168b65985c3d142a8b7e9374b8ec37c 100644 (file)
     <ClInclude Include="uarrsort.h">\r
       <Filter>collections</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="uelement.h">\r
+      <Filter>collections</Filter>\r
+    </ClInclude>\r
     <ClInclude Include="uenumimp.h">\r
       <Filter>collections</Filter>\r
     </ClInclude>\r
index 3a8690812c0d1bb5fbb5490a6752e3ae82479860..c5e4dc42a136b03c6f77ff6101bad7c9f099499f 100644 (file)
@@ -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 (file)
index 0000000..c517775
--- /dev/null
@@ -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__ */
index bf3275c59015095417f85c91d1d624a2e59fe08e..ec4c630dc7d9ddaeb9e82cd096f01d16213ac716 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "unicode/utypes.h"
 #include "cmemory.h"
+#include "uelement.h"
 
 /**
  * UHashtable stores key-value pairs and does moderately fast lookup
 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
index 9ff9ae58f2a4c26f43d040b17ade4bfcbf4a9bd8..bc204bfef669ede4a31eb651a4aa7e7a1aececc3 100644 (file)
 #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);
index f181cd3f01836e38620de0521066b70233075a02..3df71d75415f9b3732cde9ab78ec01d182742d9f 100644 (file)
@@ -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) {
index 4dda68a1813639bdb3cd643124d269f531e18a1d..bab50d4ffbc31ef8751b1f5f460fdc8045308054 100644 (file)
@@ -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;
index 76118bce99a5272089994dcbb9e82d1706fd53be..c58de7ba1f53364b323394d7e572a6f3c0ba09fc 100644 (file)
@@ -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)
 {
 }
index 2a566ed21f6b7af382ec67e3681bf7ce1a47dd46..a5adaa058ee52a844c598c0a7c36ed1025f5157c 100644 (file)
@@ -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<count; i++) {
             key.pointer = &other.elements[i];
             if (!(*comparer)(key, elements[i])) {
@@ -286,19 +287,19 @@ UBool   UVector::equals(const UVector &other) const {
 
 
 int32_t UVector::indexOf(void* obj, int32_t startIndex) const {
-    UHashTok key;
+    UElement key;
     key.pointer = obj;
     return indexOf(key, startIndex, HINT_KEY_POINTER);
 }
 
 int32_t UVector::indexOf(int32_t obj, int32_t startIndex) const {
-    UHashTok key;
+    UElement key;
     key.integer = obj;
     return indexOf(key, startIndex, HINT_KEY_INTEGER);
 }
 
 // This only works if this object has a non-null comparer
-int32_t UVector::indexOf(UHashTok key, int32_t startIndex, int8_t hint) const {
+int32_t UVector::indexOf(UElement key, int32_t startIndex, int8_t hint) const {
     int32_t i;
     if (comparer != 0) {
         for (i=startIndex; i<count; ++i) {
@@ -339,12 +340,12 @@ UBool UVector::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) {
         if (newCap < minimumCapacity) {
             newCap = minimumCapacity;
         }
-        if (newCap > (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<newSize; ++i) {
@@ -403,8 +404,8 @@ UObjectDeleter *UVector::setDeleter(UObjectDeleter *d) {
     return old;
 }
 
-UKeyComparator *UVector::setComparer(UKeyComparator *d) {
-    UKeyComparator *old = comparer;
+UElementsAreEqual *UVector::setComparer(UElementsAreEqual *d) {
+    UElementsAreEqual *old = comparer;
     comparer = d;
     return old;
 }
@@ -436,10 +437,10 @@ void* UVector::orphanElementAt(int32_t index) {
  * as defined by 'compare'.  The current elements are assumed to
  * be sorted already.
  */
-void UVector::sortedInsert(void* obj, USortComparator *compare, UErrorCode& ec) {
-    UHashTok tok;
-    tok.pointer = obj;
-    sortedInsert(tok, compare, ec);
+void UVector::sortedInsert(void* obj, UElementComparator *compare, UErrorCode& ec) {
+    UElement e;
+    e.pointer = obj;
+    sortedInsert(e, compare, ec);
 }
 
 /**
@@ -447,14 +448,14 @@ void UVector::sortedInsert(void* obj, USortComparator *compare, UErrorCode& ec)
  * as defined by 'compare'.  The current elements are assumed to
  * be sorted already.
  */
-void UVector::sortedInsert(int32_t obj, USortComparator *compare, UErrorCode& ec) {
-    UHashTok tok;
-    tok.integer = obj;
-    sortedInsert(tok, compare, ec);
+void UVector::sortedInsert(int32_t obj, UElementComparator *compare, UErrorCode& ec) {
+    UElement e;
+    e.integer = obj;
+    sortedInsert(e, compare, ec);
 }
 
 // ASSUME elements[] IS CURRENTLY SORTED
-void UVector::sortedInsert(UHashTok tok, USortComparator *compare, UErrorCode& ec) {
+void UVector::sortedInsert(UElement e, UElementComparator *compare, UErrorCode& ec) {
     // Perform a binary search for the location to insert tok at.  Tok
     // will be inserted between two elements a and b such that a <=
     // tok && tok < b, where there is a 'virtual' elements[-1] always
@@ -463,7 +464,7 @@ void UVector::sortedInsert(UHashTok tok, USortComparator *compare, UErrorCode& e
     int32_t min = 0, max = count;
     while (min != max) {
         int32_t probe = (min + max) / 2;
-        int8_t c = (*compare)(elements[probe], tok);
+        int8_t c = (*compare)(elements[probe], e);
         if (c > 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<USortComparator * const *>(context);
-    UHashTok tok1 = *static_cast<const UHashTok *>(left);
-    UHashTok tok2 = *static_cast<const UHashTok *>(right);
-    int32_t result = (*compare)(tok1, tok2);
+    UElementComparator *compare = *static_cast<UElementComparator * const *>(context);
+    UElement e1 = *static_cast<const UElement *>(left);
+    UElement e2 = *static_cast<const UElement *>(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<const UHashTok *>(left);
-    const UHashTok *tok2 = static_cast<const UHashTok *>(right);
-    int32_t result = tok1->integer < tok2->integer? -1 :
-                     tok1->integer == tok2->integer? 0 : 1;
+    const UElement *e1 = static_cast<const UElement *>(left);
+    const UElement *e2 = static_cast<const UElement *>(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);
     }
 }
index c28ddd317c65a012402c3a9b12a139155fa112d7..a04176266f45760ac778cfdfa224b1618e2a4d9e 100644 (file)
 
 #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);
-
 /**
  * <p>Ultralightweight C++ implementation of a <tt>void*</tt> 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();
 
index a4bb522a69b61f02acf33f7b833405be8cf79449..2247a45ff448d5c7b4c13557afe4a69d1ae9ff4e 100644 (file)
@@ -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<const UHashTok *>(left);
-    const UHashTok *rightTok = static_cast<const UHashTok *>(right);
-    const UnicodeString *leftString  = static_cast<const UnicodeString *>(leftTok->pointer);
-    const UnicodeString *rightString = static_cast<const UnicodeString *>(rightTok->pointer);
+    const UElement *leftElement = static_cast<const UElement *>(left);
+    const UElement *rightElement = static_cast<const UElement *>(right);
+    const UnicodeString *leftString  = static_cast<const UnicodeString *>(leftElement->pointer);
+    const UnicodeString *rightString = static_cast<const UnicodeString *>(rightElement->pointer);
     const Collator *col = static_cast<const Collator *>(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<const UHashTok *>(left);
-    const UHashTok *rightTok = static_cast<const UHashTok *>(right);
-    const AlphabeticIndex::Record *leftRec  = static_cast<const AlphabeticIndex::Record *>(leftTok->pointer);
-    const AlphabeticIndex::Record *rightRec = static_cast<const AlphabeticIndex::Record *>(rightTok->pointer);
+    const UElement *leftElement = static_cast<const UElement *>(left);
+    const UElement *rightElement = static_cast<const UElement *>(right);
+    const AlphabeticIndex::Record *leftRec  = static_cast<const AlphabeticIndex::Record *>(leftElement->pointer);
+    const AlphabeticIndex::Record *rightRec = static_cast<const AlphabeticIndex::Record *>(rightElement->pointer);
     const Collator *col = static_cast<const Collator *>(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<const UHashTok *>(left);
-    const UHashTok *rightTok = static_cast<const UHashTok *>(right);
-    const UnicodeString *s1  = static_cast<const UnicodeString *>(leftTok->pointer);
-    const UnicodeString *s2  = static_cast<const UnicodeString *>(rightTok->pointer);
+    const UElement *leftElement  = static_cast<const UElement *>(left);
+    const UElement *rightElement = static_cast<const UElement *>(right);
+    const UnicodeString *s1  = static_cast<const UnicodeString *>(leftElement->pointer);
+    const UnicodeString *s2  = static_cast<const UnicodeString *>(rightElement->pointer);
     UErrorCode &status       = *(UErrorCode *)(context);   // Cast off both static and const.
     if (s1 == s2) {
         return 0;
index 212a809cdd8575928c0a8dc3d4d912f0c6efe26b..b3c6b5662219b71cabc487daa527c8e186e5e1a6 100644 (file)
@@ -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"
index bb4ee8192d2baddd823810ab7c84623f8347a82e..5c01a10cd319910d7455dcfbe9de9050df918629 100644 (file)
@@ -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<const char *>(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
index 0f6781012d74f565e904bca9e534a3590536ed6c..9ade99a09e59ada3ccb6aca811a4cbc3d955973f 100644 (file)
@@ -18,8 +18,6 @@
 
 #include "unicode/unistr.h"
 
-union UHashTok;
-
 U_NAMESPACE_BEGIN
 
 class Locale;
index 048ee858aac9c84167b01208102406aba05a667c..fa167a6a017c28a8e85ff1712ba587552a35228d 100644 (file)
@@ -38,8 +38,6 @@
 #include "unicode/fpositer.h"
 #include "unicode/stringpiece.h"
 
-union UHashTok;
-
 U_NAMESPACE_BEGIN
 
 class DigitList;
index f6513a2147b3f37add50e8c2e313be24c8fee274..14418c66f151d7df313cf62098aa6da35269fba4 100644 (file)
@@ -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.
  *******************************************************************************
  *
 #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
 
index 35f5dc6c6c2d538e1d415bb1bc471bc8bf6799f9..8252cc205b808fc195a74f73a12a47e0e09c6273 100644 (file)
 #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.
index 98b2f38c021a6bb479ed4f0a229afc2fe29dbd0c..43841e958ce18ff5885c49be1cbdf0ed68dd53d9 100644 (file)
@@ -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;
 }
 
index a57ed5aa71d3a450c4d73c8c86ecd1b072667b24..0f0130a2cf56539281961d2eebff7055aabb4c46 100644 (file)
@@ -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,