/*
******************************************************************************
-* Copyright (C) 1997-2004, International Business Machines
+* Copyright (C) 1997-2014, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* Date Name Description
#include "unicode/unistr.h"
#include "unicode/uobject.h"
+#include "cmemory.h"
#include "uhash.h"
U_NAMESPACE_BEGIN
*/
class U_COMMON_API Hashtable : public UMemory {
UHashtable* hash;
+ UHashtable hashObj;
- inline void init(UHashFunction *keyHash, UKeyComparator *keyComp, UErrorCode& status);
+ inline void init(UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status);
public:
/**
*/
Hashtable(UBool ignoreKeyCase, UErrorCode& status);
+ /**
+ * Construct a hashtable
+ * @param keyComp Comparator for comparing the keys
+ * @param valueComp Comparator for comparing the values
+ * @param status Error code
+ */
+ Hashtable(UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status);
+
/**
* Construct a hashtable
* @param status Error code
const UHashElement* find(const UnicodeString& key) const;
+ /**
+ * @param pos - must be UHASH_FIRST on first call, and untouched afterwards.
+ * @see uhash_nextElement
+ */
const UHashElement* nextElement(int32_t& pos) const;
+
+ UKeyComparator* setKeyComparator(UKeyComparator*keyComp);
+
+ UValueComparator* setValueComparator(UValueComparator* valueComp);
+ UBool equals(const Hashtable& that) const;
private:
Hashtable(const Hashtable &other); // forbid copying of this class
Hashtable &operator=(const Hashtable &other); // forbid copying of this class
* Implementation
********************************************************************/
-inline void Hashtable::init(UHashFunction *keyHash, UKeyComparator *keyComp, UErrorCode& status) {
+inline void Hashtable::init(UHashFunction *keyHash, UKeyComparator *keyComp,
+ UValueComparator *valueComp, UErrorCode& status) {
if (U_FAILURE(status)) {
return;
}
- hash = uhash_open(keyHash, keyComp, &status);
+ uhash_init(&hashObj, keyHash, keyComp, valueComp, &status);
if (U_SUCCESS(status)) {
- uhash_setKeyDeleter(hash, uhash_deleteUnicodeString);
+ hash = &hashObj;
+ uhash_setKeyDeleter(hash, uprv_deleteUObject);
}
}
+inline Hashtable::Hashtable(UKeyComparator *keyComp, UValueComparator *valueComp,
+ UErrorCode& status) : hash(0) {
+ init( uhash_hashUnicodeString, keyComp, valueComp, status);
+}
inline Hashtable::Hashtable(UBool ignoreKeyCase, UErrorCode& status)
: hash(0)
{
: uhash_hashUnicodeString,
ignoreKeyCase ? uhash_compareCaselessUnicodeString
: uhash_compareUnicodeString,
+ NULL,
status);
}
inline Hashtable::Hashtable(UErrorCode& status)
: hash(0)
{
- init(uhash_hashUnicodeString, uhash_compareUnicodeString, status);
+ init(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, status);
}
inline Hashtable::Hashtable()
: hash(0)
{
UErrorCode status = U_ZERO_ERROR;
- init(uhash_hashUnicodeString, uhash_compareUnicodeString, status);
+ init(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, status);
}
inline Hashtable::~Hashtable() {
- if (hash != 0) {
+ if (hash != NULL) {
uhash_close(hash);
- hash = 0;
}
}
}
inline void Hashtable::removeAll(void) {
- uhash_removeAll(hash);
+ uhash_removeAll(hash);
+}
+
+inline UKeyComparator* Hashtable::setKeyComparator(UKeyComparator*keyComp){
+ return uhash_setKeyComparator(hash, keyComp);
+}
+
+inline UValueComparator* Hashtable::setValueComparator(UValueComparator* valueComp){
+ return uhash_setValueComparator(hash, valueComp);
}
+inline UBool Hashtable::equals(const Hashtable& that)const{
+ return uhash_equals(hash, that.hash);
+}
U_NAMESPACE_END
#endif
+