ICU-1023 add uhash_xxxi and Hashtable::xxxi functions for integer values

X-SVN-Rev: 6265
This commit is contained in:
Alan Liu 2001-10-16 20:53:13 +00:00
parent 8a98ee7a0e
commit a9fc30c720
3 changed files with 120 additions and 12 deletions

View file

@ -48,10 +48,16 @@ public:
void* put(const UnicodeString& key, void* value, UErrorCode& status);
int32_t puti(const UnicodeString& key, int32_t value, UErrorCode& status);
void* get(const UnicodeString& key) const;
int32_t geti(const UnicodeString& key) const;
void* remove(const UnicodeString& key);
int32_t removei(const UnicodeString& key);
const UHashElement* find(const UnicodeString& key) const;
const UHashElement* nextElement(int32_t& pos) const;
@ -107,14 +113,26 @@ inline void* Hashtable::put(const UnicodeString& key, void* value, UErrorCode& s
return uhash_put(hash, new UnicodeString(key), value, &status);
}
inline int32_t Hashtable::puti(const UnicodeString& key, int32_t value, UErrorCode& status) {
return uhash_puti(hash, new UnicodeString(key), value, &status);
}
inline void* Hashtable::get(const UnicodeString& key) const {
return uhash_get(hash, &key);
}
inline int32_t Hashtable::geti(const UnicodeString& key) const {
return uhash_geti(hash, &key);
}
inline void* Hashtable::remove(const UnicodeString& key) {
return uhash_remove(hash, &key);
}
inline int32_t Hashtable::removei(const UnicodeString& key) {
return uhash_removei(hash, &key);
}
inline const UHashElement* Hashtable::find(const UnicodeString& key) const {
return uhash_find(hash, &key);
}

View file

@ -272,6 +272,14 @@ uhash_iget(const UHashtable *hash,
return _uhash_find(hash, keyholder, hash->keyHasher(keyholder))->value.pointer;
}
U_CAPI int32_t
uhash_geti(const UHashtable *hash,
const void* key) {
UHashTok keyholder;
keyholder.pointer = (void*) key;
return _uhash_find(hash, keyholder, hash->keyHasher(keyholder))->value.integer;
}
U_CAPI void*
uhash_put(UHashtable *hash,
void* key,
@ -294,6 +302,17 @@ uhash_iput(UHashtable *hash,
return _uhash_put(hash, keyholder, valueholder, status).pointer;
}
int32_t
uhash_puti(UHashtable *hash,
void* key,
int32_t value,
UErrorCode *status) {
UHashTok keyholder, valueholder;
keyholder.pointer = key;
valueholder.integer = value;
return _uhash_put(hash, keyholder, valueholder, status).integer;
}
U_CAPI void*
uhash_remove(UHashtable *hash,
const void* key) {
@ -310,6 +329,14 @@ uhash_iremove(UHashtable *hash,
return _uhash_remove(hash, keyholder).pointer;
}
U_CAPI int32_t
uhash_removei(UHashtable *hash,
const void* key) {
UHashTok keyholder;
keyholder.pointer = (void*) key;
return _uhash_remove(hash, keyholder).integer;
}
U_CAPI void
uhash_removeAll(UHashtable *hash) {
int32_t pos = -1;

View file

@ -281,10 +281,11 @@ U_CAPI int32_t
uhash_count(const UHashtable *hash);
/**
* Put an item in a UHashtable. If the keyDeleter is non-NULL, then
* the hashtable owns 'key' after this call. If the valueDeleter is
* non-NULL, then the hashtable owns 'value' after this call.
* Storing a NULL value is the same as calling uhash_remove().
* Put a (key=pointer, value=pointer) item in a UHashtable. If the
* keyDeleter is non-NULL, then the hashtable owns 'key' after this
* call. If the valueDeleter is non-NULL, then the hashtable owns
* 'value' after this call. Storing a NULL value is the same as
* calling uhash_remove().
* @param hash The target UHashtable.
* @param key The key to store.
* @param value The value to store, may be NULL (see above).
@ -298,7 +299,18 @@ uhash_put(UHashtable *hash,
void *value,
UErrorCode *status);
/* NEW */
/**
* Put a (key=integer, value=pointer) item in a UHashtable.
* keyDeleter must be NULL. If the valueDeleter is non-NULL, then the
* hashtable owns 'value' after this call. Storing a NULL value is
* the same as calling uhash_remove().
* @param hash The target UHashtable.
* @param key The integer key to store.
* @param value The value to store, may be NULL (see above).
* @param status A pointer to an UErrorCode to receive any errors.
* @return The previous value, or NULL if none.
* @see uhash_get
*/
U_CAPI void*
uhash_iput(UHashtable *hash,
int32_t key,
@ -306,35 +318,86 @@ uhash_iput(UHashtable *hash,
UErrorCode *status);
/**
* Get an item from a UHashtable.
* Put a (key=pointer, value=integer) item in a UHashtable. If the
* keyDeleter is non-NULL, then the hashtable owns 'key' after this
* call. valueDeleter must be NULL. Storing a 0 value is the same as
* calling uhash_remove().
* @param hash The target UHashtable.
* @param key A key stored in a hashtable
* @return The requested item, or 0 if not found.
* @param key The key to store.
* @param value The integer value to store.
* @param status A pointer to an UErrorCode to receive any errors.
* @return The previous value, or 0 if none.
* @see uhash_get
*/
U_CAPI int32_t
uhash_puti(UHashtable *hash,
void* key,
int32_t value,
UErrorCode *status);
/**
* Retrieve a pointer value from a UHashtable using a pointer key,
* as previously stored by uhash_put().
* @param hash The target UHashtable.
* @param key A pointer key stored in a hashtable
* @return The requested item, or NULL if not found.
*/
U_CAPI void*
uhash_get(const UHashtable *hash,
const void *key);
/* NEW */
/**
* Retrieve a pointer value from a UHashtable using a integer key,
* as previously stored by uhash_iput().
* @param hash The target UHashtable.
* @param key An integer key stored in a hashtable
* @return The requested item, or NULL if not found.
*/
U_CAPI void*
uhash_iget(const UHashtable *hash,
int32_t key);
/**
* Remove an item from a UHashtable.
* Retrieve an integer value from a UHashtable using a pointer key,
* as previously stored by uhash_puti().
* @param hash The target UHashtable.
* @param key A pointer key stored in a hashtable
* @return The requested item, or 0 if not found.
*/
U_CAPI int32_t
uhash_geti(const UHashtable *hash,
const void* key);
/**
* Remove an item from a UHashtable stored by uhash_put().
* @param hash The target UHashtable.
* @param key A key stored in a hashtable
* @return The item removed, or 0 if not found.
* @return The item removed, or NULL if not found.
*/
U_CAPI void*
uhash_remove(UHashtable *hash,
const void *key);
/* NEW */
/**
* Remove an item from a UHashtable stored by uhash_iput().
* @param hash The target UHashtable.
* @param key An integer key stored in a hashtable
* @return The item removed, or NULL if not found.
*/
U_CAPI void*
uhash_iremove(UHashtable *hash,
int32_t key);
/**
* Remove an item from a UHashtable stored by uhash_puti().
* @param hash The target UHashtable.
* @param key An key stored in a hashtable
* @return The item removed, or 0 if not found.
*/
U_CAPI int32_t
uhash_removei(UHashtable *hash,
const void* key);
/**
* Remove all items from a UHashtable.
* @param hash The target UHashtable.