annotate modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/common/hash.h @ 11038:20a8447c71c6

8207159: Update ICU to version 62.1 Reviewed-by: mbilla, kcr, ghb
author arajkumar
date Fri, 24 Aug 2018 15:06:40 +0530
parents fee4ef5c87df
children
rev   line source
arajkumar@11038 1 // © 2016 and later: Unicode, Inc. and others.
arajkumar@11038 2 // License & terms of use: http://www.unicode.org/copyright.html
ghb@10550 3 /*
ghb@10550 4 ******************************************************************************
arajkumar@11038 5 * Copyright (C) 1997-2014, International Business Machines
ghb@10550 6 * Corporation and others. All Rights Reserved.
ghb@10550 7 ******************************************************************************
ghb@10550 8 * Date Name Description
ghb@10550 9 * 03/28/00 aliu Creation.
ghb@10550 10 ******************************************************************************
ghb@10550 11 */
ghb@10550 12
ghb@10550 13 #ifndef HASH_H
ghb@10550 14 #define HASH_H
ghb@10550 15
ghb@10550 16 #include "unicode/unistr.h"
ghb@10550 17 #include "unicode/uobject.h"
ghb@10550 18 #include "cmemory.h"
ghb@10550 19 #include "uhash.h"
ghb@10550 20
ghb@10550 21 U_NAMESPACE_BEGIN
ghb@10550 22
ghb@10550 23 /**
ghb@10550 24 * Hashtable is a thin C++ wrapper around UHashtable, a general-purpose void*
ghb@10550 25 * hashtable implemented in C. Hashtable is designed to be idiomatic and
ghb@10550 26 * easy-to-use in C++.
ghb@10550 27 *
ghb@10550 28 * Hashtable is an INTERNAL CLASS.
ghb@10550 29 */
ghb@10550 30 class U_COMMON_API Hashtable : public UMemory {
ghb@10550 31 UHashtable* hash;
ghb@10550 32 UHashtable hashObj;
ghb@10550 33
ghb@10550 34 inline void init(UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status);
ghb@10550 35
arajkumar@11038 36 inline void initSize(UHashFunction *keyHash, UKeyComparator *keyComp, UValueComparator *valueComp, int32_t size, UErrorCode& status);
arajkumar@11038 37
ghb@10550 38 public:
ghb@10550 39 /**
ghb@10550 40 * Construct a hashtable
ghb@10550 41 * @param ignoreKeyCase If true, keys are case insensitive.
ghb@10550 42 * @param status Error code
ghb@10550 43 */
ghb@10550 44 Hashtable(UBool ignoreKeyCase, UErrorCode& status);
ghb@10550 45
ghb@10550 46 /**
ghb@10550 47 * Construct a hashtable
arajkumar@11038 48 * @param ignoreKeyCase If true, keys are case insensitive.
arajkumar@11038 49 * @param size initial size allocation
arajkumar@11038 50 * @param status Error code
arajkumar@11038 51 */
arajkumar@11038 52 Hashtable(UBool ignoreKeyCase, int32_t size, UErrorCode& status);
arajkumar@11038 53
arajkumar@11038 54 /**
arajkumar@11038 55 * Construct a hashtable
ghb@10550 56 * @param keyComp Comparator for comparing the keys
ghb@10550 57 * @param valueComp Comparator for comparing the values
ghb@10550 58 * @param status Error code
ghb@10550 59 */
ghb@10550 60 Hashtable(UKeyComparator *keyComp, UValueComparator *valueComp, UErrorCode& status);
ghb@10550 61
ghb@10550 62 /**
ghb@10550 63 * Construct a hashtable
ghb@10550 64 * @param status Error code
ghb@10550 65 */
ghb@10550 66 Hashtable(UErrorCode& status);
ghb@10550 67
ghb@10550 68 /**
ghb@10550 69 * Construct a hashtable, _disregarding any error_. Use this constructor
ghb@10550 70 * with caution.
ghb@10550 71 */
ghb@10550 72 Hashtable();
ghb@10550 73
ghb@10550 74 /**
ghb@10550 75 * Non-virtual destructor; make this virtual if Hashtable is subclassed
ghb@10550 76 * in the future.
ghb@10550 77 */
ghb@10550 78 ~Hashtable();
ghb@10550 79
ghb@10550 80 UObjectDeleter *setValueDeleter(UObjectDeleter *fn);
ghb@10550 81
ghb@10550 82 int32_t count() const;
ghb@10550 83
ghb@10550 84 void* put(const UnicodeString& key, void* value, UErrorCode& status);
ghb@10550 85
ghb@10550 86 int32_t puti(const UnicodeString& key, int32_t value, UErrorCode& status);
ghb@10550 87
ghb@10550 88 void* get(const UnicodeString& key) const;
ghb@10550 89
ghb@10550 90 int32_t geti(const UnicodeString& key) const;
ghb@10550 91
ghb@10550 92 void* remove(const UnicodeString& key);
ghb@10550 93
ghb@10550 94 int32_t removei(const UnicodeString& key);
ghb@10550 95
ghb@10550 96 void removeAll(void);
ghb@10550 97
ghb@10550 98 const UHashElement* find(const UnicodeString& key) const;
ghb@10550 99
arajkumar@11038 100 /**
arajkumar@11038 101 * @param pos - must be UHASH_FIRST on first call, and untouched afterwards.
arajkumar@11038 102 * @see uhash_nextElement
arajkumar@11038 103 */
ghb@10550 104 const UHashElement* nextElement(int32_t& pos) const;
ghb@10550 105
ghb@10550 106 UKeyComparator* setKeyComparator(UKeyComparator*keyComp);
ghb@10550 107
ghb@10550 108 UValueComparator* setValueComparator(UValueComparator* valueComp);
ghb@10550 109
ghb@10550 110 UBool equals(const Hashtable& that) const;
ghb@10550 111 private:
ghb@10550 112 Hashtable(const Hashtable &other); // forbid copying of this class
ghb@10550 113 Hashtable &operator=(const Hashtable &other); // forbid copying of this class
ghb@10550 114 };
ghb@10550 115
ghb@10550 116 /*********************************************************************
ghb@10550 117 * Implementation
ghb@10550 118 ********************************************************************/
ghb@10550 119
ghb@10550 120 inline void Hashtable::init(UHashFunction *keyHash, UKeyComparator *keyComp,
ghb@10550 121 UValueComparator *valueComp, UErrorCode& status) {
ghb@10550 122 if (U_FAILURE(status)) {
ghb@10550 123 return;
ghb@10550 124 }
ghb@10550 125 uhash_init(&hashObj, keyHash, keyComp, valueComp, &status);
ghb@10550 126 if (U_SUCCESS(status)) {
ghb@10550 127 hash = &hashObj;
ghb@10550 128 uhash_setKeyDeleter(hash, uprv_deleteUObject);
ghb@10550 129 }
ghb@10550 130 }
ghb@10550 131
arajkumar@11038 132 inline void Hashtable::initSize(UHashFunction *keyHash, UKeyComparator *keyComp,
arajkumar@11038 133 UValueComparator *valueComp, int32_t size, UErrorCode& status) {
arajkumar@11038 134 if (U_FAILURE(status)) {
arajkumar@11038 135 return;
arajkumar@11038 136 }
arajkumar@11038 137 uhash_initSize(&hashObj, keyHash, keyComp, valueComp, size, &status);
arajkumar@11038 138 if (U_SUCCESS(status)) {
arajkumar@11038 139 hash = &hashObj;
arajkumar@11038 140 uhash_setKeyDeleter(hash, uprv_deleteUObject);
arajkumar@11038 141 }
arajkumar@11038 142 }
arajkumar@11038 143
ghb@10550 144 inline Hashtable::Hashtable(UKeyComparator *keyComp, UValueComparator *valueComp,
ghb@10550 145 UErrorCode& status) : hash(0) {
ghb@10550 146 init( uhash_hashUnicodeString, keyComp, valueComp, status);
ghb@10550 147 }
arajkumar@11038 148
ghb@10550 149 inline Hashtable::Hashtable(UBool ignoreKeyCase, UErrorCode& status)
ghb@10550 150 : hash(0)
ghb@10550 151 {
ghb@10550 152 init(ignoreKeyCase ? uhash_hashCaselessUnicodeString
ghb@10550 153 : uhash_hashUnicodeString,
ghb@10550 154 ignoreKeyCase ? uhash_compareCaselessUnicodeString
ghb@10550 155 : uhash_compareUnicodeString,
ghb@10550 156 NULL,
ghb@10550 157 status);
ghb@10550 158 }
ghb@10550 159
arajkumar@11038 160 inline Hashtable::Hashtable(UBool ignoreKeyCase, int32_t size, UErrorCode& status)
arajkumar@11038 161 : hash(0)
arajkumar@11038 162 {
arajkumar@11038 163 initSize(ignoreKeyCase ? uhash_hashCaselessUnicodeString
arajkumar@11038 164 : uhash_hashUnicodeString,
arajkumar@11038 165 ignoreKeyCase ? uhash_compareCaselessUnicodeString
arajkumar@11038 166 : uhash_compareUnicodeString,
arajkumar@11038 167 NULL, size,
arajkumar@11038 168 status);
arajkumar@11038 169 }
arajkumar@11038 170
ghb@10550 171 inline Hashtable::Hashtable(UErrorCode& status)
ghb@10550 172 : hash(0)
ghb@10550 173 {
ghb@10550 174 init(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, status);
ghb@10550 175 }
ghb@10550 176
ghb@10550 177 inline Hashtable::Hashtable()
ghb@10550 178 : hash(0)
ghb@10550 179 {
ghb@10550 180 UErrorCode status = U_ZERO_ERROR;
ghb@10550 181 init(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, status);
ghb@10550 182 }
ghb@10550 183
ghb@10550 184 inline Hashtable::~Hashtable() {
ghb@10550 185 if (hash != NULL) {
ghb@10550 186 uhash_close(hash);
ghb@10550 187 }
ghb@10550 188 }
ghb@10550 189
ghb@10550 190 inline UObjectDeleter *Hashtable::setValueDeleter(UObjectDeleter *fn) {
ghb@10550 191 return uhash_setValueDeleter(hash, fn);
ghb@10550 192 }
ghb@10550 193
ghb@10550 194 inline int32_t Hashtable::count() const {
ghb@10550 195 return uhash_count(hash);
ghb@10550 196 }
ghb@10550 197
ghb@10550 198 inline void* Hashtable::put(const UnicodeString& key, void* value, UErrorCode& status) {
ghb@10550 199 return uhash_put(hash, new UnicodeString(key), value, &status);
ghb@10550 200 }
ghb@10550 201
ghb@10550 202 inline int32_t Hashtable::puti(const UnicodeString& key, int32_t value, UErrorCode& status) {
ghb@10550 203 return uhash_puti(hash, new UnicodeString(key), value, &status);
ghb@10550 204 }
ghb@10550 205
ghb@10550 206 inline void* Hashtable::get(const UnicodeString& key) const {
ghb@10550 207 return uhash_get(hash, &key);
ghb@10550 208 }
ghb@10550 209
ghb@10550 210 inline int32_t Hashtable::geti(const UnicodeString& key) const {
ghb@10550 211 return uhash_geti(hash, &key);
ghb@10550 212 }
ghb@10550 213
ghb@10550 214 inline void* Hashtable::remove(const UnicodeString& key) {
ghb@10550 215 return uhash_remove(hash, &key);
ghb@10550 216 }
ghb@10550 217
ghb@10550 218 inline int32_t Hashtable::removei(const UnicodeString& key) {
ghb@10550 219 return uhash_removei(hash, &key);
ghb@10550 220 }
ghb@10550 221
ghb@10550 222 inline const UHashElement* Hashtable::find(const UnicodeString& key) const {
ghb@10550 223 return uhash_find(hash, &key);
ghb@10550 224 }
ghb@10550 225
ghb@10550 226 inline const UHashElement* Hashtable::nextElement(int32_t& pos) const {
ghb@10550 227 return uhash_nextElement(hash, &pos);
ghb@10550 228 }
ghb@10550 229
ghb@10550 230 inline void Hashtable::removeAll(void) {
ghb@10550 231 uhash_removeAll(hash);
ghb@10550 232 }
ghb@10550 233
ghb@10550 234 inline UKeyComparator* Hashtable::setKeyComparator(UKeyComparator*keyComp){
ghb@10550 235 return uhash_setKeyComparator(hash, keyComp);
ghb@10550 236 }
ghb@10550 237
ghb@10550 238 inline UValueComparator* Hashtable::setValueComparator(UValueComparator* valueComp){
ghb@10550 239 return uhash_setValueComparator(hash, valueComp);
ghb@10550 240 }
ghb@10550 241
ghb@10550 242 inline UBool Hashtable::equals(const Hashtable& that)const{
ghb@10550 243 return uhash_equals(hash, that.hash);
ghb@10550 244 }
ghb@10550 245 U_NAMESPACE_END
ghb@10550 246
ghb@10550 247 #endif
ghb@10550 248