ICU-8617 move UHashTok into lower-level uelement.h (new) and rename to UElement to share with UVector

X-SVN-Rev: 30272
This commit is contained in:
Markus Scherer 2011-07-04 23:51:56 +00:00
parent a74d503edb
commit 744d1f3a19
20 changed files with 201 additions and 180 deletions

View File

@ -569,6 +569,7 @@
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
</CustomBuild>
<ClInclude Include="uelement.h" />
<ClInclude Include="uenumimp.h" />
<ClInclude Include="uhash.h" />
<ClInclude Include="ulist.h" />

View File

@ -582,6 +582,9 @@
<ClInclude Include="uarrsort.h">
<Filter>collections</Filter>
</ClInclude>
<ClInclude Include="uelement.h">
<Filter>collections</Filter>
</ClInclude>
<ClInclude Include="uenumimp.h">
<Filter>collections</Filter>
</ClInclude>

View 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

View File

@ -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__ */

View 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
@ -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

View File

@ -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);

View 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) {

View 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;

View 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)
{
}

View 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);
}
}

View File

@ -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);
/**
* <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();

View 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;

View 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"

View 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

View File

@ -18,8 +18,6 @@
#include "unicode/unistr.h"
union UHashTok;
U_NAMESPACE_BEGIN
class Locale;

View File

@ -38,8 +38,6 @@
#include "unicode/fpositer.h"
#include "unicode/stringpiece.h"
union UHashTok;
U_NAMESPACE_BEGIN
class DigitList;

View 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.
*******************************************************************************
*
@ -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

View File

@ -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.

View 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;
}

View 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,