ICU-149 make TaggedList use Hashtable

X-SVN-Rev: 1018
This commit is contained in:
Alan Liu 2000-03-29 19:17:17 +00:00
parent 0df6047dc5
commit 61c6f2fa23
3 changed files with 48 additions and 69 deletions

View File

@ -79,54 +79,38 @@ String2dList::getStaticClassID()
//-----------------------------------------------------------------------------
TaggedList::TaggedList()
{
UErrorCode err = U_ZERO_ERROR;
fHashtableValues = uhash_open((UHashFunction)uhash_OLD_hashUString,
uhash_OLD_pointerComparator, &err);
uhash_setValueDeleter(fHashtableValues, deleteValue);
fHashtableKeys = uhash_open((UHashFunction)uhash_OLD_hashUString,
uhash_OLD_pointerComparator, &err);
TaggedList::TaggedList() {
UErrorCode status = U_ZERO_ERROR;
hash = new Hashtable(status);
hash->setValueDeleter(uhash_deleteUnicodeString);
}
TaggedList::~TaggedList()
{
uhash_close(fHashtableValues);
uhash_close(fHashtableKeys);
TaggedList::~TaggedList() {
delete hash;
}
int32_t TaggedList::count() const {
return hash->count();
}
void
TaggedList::put(const UnicodeString& tag,
const UnicodeString& data)
{
UErrorCode err = U_ZERO_ERROR;
uhash_OLD_putKey(fHashtableValues,
tag.hashCode() & 0x7FFFFFFF,
(new UnicodeString(data)),
&err);
uhash_OLD_putKey(fHashtableKeys,
uhash_count(fHashtableValues),
(new UnicodeString(tag)),
&err);
const UnicodeString& data) {
UErrorCode status = U_ZERO_ERROR;
hash->put(tag, new UnicodeString(data), status);
}
const UnicodeString*
TaggedList::get(const UnicodeString& tag) const
{
return (const UnicodeString*)
uhash_OLD_get(fHashtableValues, tag.hashCode() & 0x7FFFFFFF);
TaggedList::get(const UnicodeString& tag) const {
return (const UnicodeString*) hash->get(tag);
}
void
TaggedList::deleteValue(void *value)
{
delete (UnicodeString*)value;
bool_t TaggedList::nextElement(const UnicodeString*& key,
const UnicodeString*& value,
int32_t& pos) const {
return hash->nextElement(key, (void*&)value, pos);
}
UClassID
TaggedList::getDynamicClassID() const
{ return getStaticClassID(); }

View File

@ -19,7 +19,7 @@
#define RBDATA_H 1
#include "unicode/utypes.h"
#include "uhash.h"
#include "hash.h"
#include "unicode/unistr.h"
/**
@ -74,19 +74,23 @@ public:
*/
class TaggedList : public ResourceBundleData
{
Hashtable *hash;
public:
TaggedList();
virtual ~TaggedList();
void put(const UnicodeString& tag, const UnicodeString& data);
const UnicodeString* get(const UnicodeString& tag) const;
virtual UClassID getDynamicClassID(void) const;
static UClassID getStaticClassID(void);
TaggedList();
virtual ~TaggedList();
void put(const UnicodeString& tag, const UnicodeString& data);
const UnicodeString* get(const UnicodeString& tag) const;
bool_t nextElement(const UnicodeString*& key,
const UnicodeString*& value,
int32_t& pos) const;
int32_t count() const;
static void U_CALLCONV deleteValue(void* value);
static UClassID fgClassID;
UHashtable *fHashtableValues;
UHashtable *fHashtableKeys;
virtual UClassID getDynamicClassID(void) const;
static UClassID getStaticClassID(void);
static UClassID fgClassID;
};
#endif

View File

@ -844,19 +844,14 @@ getTaggedArrayUCharsImplementation( const ResourceBundle* bundle,
return;
}
UHashtable* forEnumerationValues = ((TaggedList*)data)->fHashtableValues;
void* value;
numItems = 0;
int32_t pos = -1;
while(value = uhash_OLD_nextElement(forEnumerationValues, &pos)) {
if(numItems < maxItems) {
itemTags[numItems] =
((const UnicodeString*)uhash_OLD_get(((TaggedList*)data)->fHashtableKeys,
numItems+1))->getUChars();
items[numItems] = ((const UnicodeString*)value)->getUChars();
}
numItems++;
const UnicodeString *key, *value;
while (((TaggedList*)data)->nextElement(key, value, pos) &&
numItems < maxItems) {
itemTags[numItems] = key->getUChars();
items[numItems] = value->getUChars();
numItems++;
}
}
@ -879,24 +874,20 @@ ResourceBundle::getTaggedArray( const char *resourceTag,
// go through the resource once and count how many items there are
numItems = uhash_count(((TaggedList*)data)->fHashtableValues);
numItems = ((TaggedList*)data)->count();
// now create the string arrays and go through the hash table again, this
// time copying the keys and values into the string arrays
itemTags = new UnicodeString[numItems];
items = new UnicodeString[numItems];
UHashtable* forEnumerationValues = ((TaggedList*)data)->fHashtableValues;
void* value;
numItems = 0;
int32_t pos = -1;
while(value = uhash_OLD_nextElement(forEnumerationValues, &pos)) {
itemTags[numItems] =
*((const UnicodeString*)uhash_OLD_get(((TaggedList*)data)->fHashtableKeys,
numItems+1));
items[numItems] = *((const UnicodeString*)value);
numItems++;
const UnicodeString *key, *value;
while (((TaggedList*)data)->nextElement(key, value, pos)) {
itemTags[numItems] = *key;
items[numItems] = *value;
numItems++;
}
}
@ -1025,7 +1016,7 @@ T_ResourceBundle_countArrayItemsImplementation(const ResourceBundle* resourceBun
numItems = ((StringList*)data)->fCount;
}
else if(rbkeyClassID == TaggedList::getStaticClassID()) {
numItems = uhash_count(((TaggedList*)data)->fHashtableValues);
numItems = ((TaggedList*)data)->count();
}
else if(rbkeyClassID == String2dList::getStaticClassID()) {
numItems = ((String2dList*)data)->fRowCount;