+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
-* Copyright (C) 1997-2014, International Business Machines
+* Copyright (C) 1997-2015, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* Date Name Description
* hashcode. During iteration an element may be deleted by calling
* uhash_removeElement(); iteration may safely continue thereafter.
* The uhash_remove() function may also be safely called in
- * mid-iteration. However, if uhash_put() is called during iteration
- * then the iteration will be out of sync. Under no circumstances
- * should the UHashElement returned by uhash_nextElement be modified
- * directly.
+ * mid-iteration. If uhash_put() is called during iteration,
+ * the iteration is still guaranteed to terminate reasonably, but
+ * there is no guarantee that every element will be returned or that
+ * some won't be returned more than once.
+ *
+ * Under no circumstances should the UHashElement returned by
+ * uhash_nextElement be modified directly.
*
* By default, the hashtable grows when necessary, but never shrinks,
* even if all items are removed. For most applications this is
* If NULL won't do anything */
/* Size parameters */
-
+
int32_t count; /* The number of key-value pairs in this table.
* 0 <= count <= length. In practice we
* never let count == length (see code). */
* and values. Must be prime. */
/* Rehashing thresholds */
-
+
int32_t highWaterMark; /* If count > highWaterMark, rehash */
int32_t lowWaterMark; /* If count < lowWaterMark, rehash */
float highWaterRatio; /* 0..1; high water as a fraction of length */
float lowWaterRatio; /* 0..1; low water as a fraction of length */
-
+
int8_t primeIndex; /* Index into our prime table for length.
* length == PRIMES[primeIndex] */
UBool allocated; /* Was this UHashtable allocated? */
* @return A pointer to a UHashtable, or 0 if an error occurred.
* @see uhash_openSize
*/
-U_CAPI UHashtable* U_EXPORT2
+U_CAPI UHashtable* U_EXPORT2
uhash_open(UHashFunction *keyHash,
UKeyComparator *keyComp,
UValueComparator *valueComp,
* @return A pointer to a UHashtable, or 0 if an error occurred.
* @see uhash_open
*/
-U_CAPI UHashtable* U_EXPORT2
+U_CAPI UHashtable* U_EXPORT2
uhash_openSize(UHashFunction *keyHash,
UKeyComparator *keyComp,
UValueComparator *valueComp,
* @return A pointer to a UHashtable, or 0 if an error occurred.
* @see uhash_openSize
*/
-U_CAPI UHashtable* U_EXPORT2
+U_CAPI UHashtable* U_EXPORT2
uhash_init(UHashtable *hash,
UHashFunction *keyHash,
UKeyComparator *keyComp,
UValueComparator *valueComp,
UErrorCode *status);
+/**
+ * Initialize an existing UHashtable.
+ * @param keyHash A pointer to the key hashing function. Must not be
+ * NULL.
+ * @param keyComp A pointer to the function that compares keys. Must
+ * not be NULL.
+ * @param size The initial capacity of this hash table.
+ * @param status A pointer to an UErrorCode to receive any errors.
+ * @return A pointer to a UHashtable, or 0 if an error occurred.
+ * @see uhash_openSize
+ */
+U_CAPI UHashtable* U_EXPORT2
+uhash_initSize(UHashtable *hash,
+ UHashFunction *keyHash,
+ UKeyComparator *keyComp,
+ UValueComparator *valueComp,
+ int32_t size,
+ UErrorCode *status);
+
/**
* Close a UHashtable, releasing the memory used.
* @param hash The UHashtable to close. If hash is NULL no operation is performed.
*/
-U_CAPI void U_EXPORT2
+U_CAPI void U_EXPORT2
uhash_close(UHashtable *hash);
* @param fn the function to be used hash keys; must not be NULL
* @return the previous key hasher; non-NULL
*/
-U_CAPI UHashFunction *U_EXPORT2
+U_CAPI UHashFunction *U_EXPORT2
uhash_setKeyHasher(UHashtable *hash, UHashFunction *fn);
/**
* @param fn the function to be used compare keys; must not be NULL
* @return the previous key comparator; non-NULL
*/
-U_CAPI UKeyComparator *U_EXPORT2
+U_CAPI UKeyComparator *U_EXPORT2
uhash_setKeyComparator(UHashtable *hash, UKeyComparator *fn);
/**
* @param fn the function to be used compare keys; must not be NULL
* @return the previous key comparator; non-NULL
*/
-U_CAPI UValueComparator *U_EXPORT2
+U_CAPI UValueComparator *U_EXPORT2
uhash_setValueComparator(UHashtable *hash, UValueComparator *fn);
/**
* @param fn the function to be used delete keys, or NULL
* @return the previous key deleter; may be NULL
*/
-U_CAPI UObjectDeleter *U_EXPORT2
+U_CAPI UObjectDeleter *U_EXPORT2
uhash_setKeyDeleter(UHashtable *hash, UObjectDeleter *fn);
/**
* @param fn the function to be used delete values, or NULL
* @return the previous value deleter; may be NULL
*/
-U_CAPI UObjectDeleter *U_EXPORT2
+U_CAPI UObjectDeleter *U_EXPORT2
uhash_setValueDeleter(UHashtable *hash, UObjectDeleter *fn);
/**
* @param hash The UHashtable to set
* @param policy The way the hashtable resizes itself, {U_GROW, U_GROW_AND_SHRINK, U_FIXED}
*/
-U_CAPI void U_EXPORT2
+U_CAPI void U_EXPORT2
uhash_setResizePolicy(UHashtable *hash, enum UHashResizePolicy policy);
/**
* @param hash The UHashtable to query.
* @return The number of key-value pairs stored in hash.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_count(const UHashtable *hash);
/**
* @return The previous value, or NULL if none.
* @see uhash_get
*/
-U_CAPI void* U_EXPORT2
+U_CAPI void* U_EXPORT2
uhash_put(UHashtable *hash,
void *key,
void *value,
* @return The previous value, or NULL if none.
* @see uhash_get
*/
-U_CAPI void* U_EXPORT2
+U_CAPI void* U_EXPORT2
uhash_iput(UHashtable *hash,
int32_t key,
void* value,
* @return The previous value, or 0 if none.
* @see uhash_get
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_puti(UHashtable *hash,
void* key,
int32_t value,
* @return The previous value, or 0 if none.
* @see uhash_get
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_iputi(UHashtable *hash,
int32_t key,
int32_t value,
* @param key A pointer key stored in a hashtable
* @return The requested item, or NULL if not found.
*/
-U_CAPI void* U_EXPORT2
-uhash_get(const UHashtable *hash,
+U_CAPI void* U_EXPORT2
+uhash_get(const UHashtable *hash,
const void *key);
/**
* @param key An integer key stored in a hashtable
* @return The requested item, or NULL if not found.
*/
-U_CAPI void* U_EXPORT2
+U_CAPI void* U_EXPORT2
uhash_iget(const UHashtable *hash,
int32_t key);
* @param key A pointer key stored in a hashtable
* @return The requested item, or 0 if not found.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_geti(const UHashtable *hash,
const void* key);
/**
* @param key An integer key stored in a hashtable
* @return The requested item, or 0 if not found.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_igeti(const UHashtable *hash,
int32_t key);
* @param key A key stored in a hashtable
* @return The item removed, or NULL if not found.
*/
-U_CAPI void* U_EXPORT2
+U_CAPI void* U_EXPORT2
uhash_remove(UHashtable *hash,
const void *key);
* @param key An integer key stored in a hashtable
* @return The item removed, or NULL if not found.
*/
-U_CAPI void* U_EXPORT2
+U_CAPI void* U_EXPORT2
uhash_iremove(UHashtable *hash,
int32_t key);
* @param key An key stored in a hashtable
* @return The item removed, or 0 if not found.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_removei(UHashtable *hash,
const void* key);
* @param key An integer key stored in a hashtable
* @return The item removed, or 0 if not found.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_iremovei(UHashtable *hash,
int32_t key);
* Remove all items from a UHashtable.
* @param hash The target UHashtable.
*/
-U_CAPI void U_EXPORT2
+U_CAPI void U_EXPORT2
uhash_removeAll(UHashtable *hash);
/**
* @param key A key stored in a hashtable
* @return a hash element, or NULL if the key is not found.
*/
-U_CAPI const UHashElement* U_EXPORT2
+U_CAPI const UHashElement* U_EXPORT2
uhash_find(const UHashtable *hash, const void* key);
/**
* @return a hash element, or NULL if no further key-value pairs
* exist in the table.
*/
-U_CAPI const UHashElement* U_EXPORT2
+U_CAPI const UHashElement* U_EXPORT2
uhash_nextElement(const UHashtable *hash,
int32_t *pos);
* modified.
* @return the value that was removed.
*/
-U_CAPI void* U_EXPORT2
+U_CAPI void* U_EXPORT2
uhash_removeElement(UHashtable *hash, const UHashElement* e);
/********************************************************************
* @param i The given integer
* @return a UHashTok for an integer.
*/
-/*U_CAPI UHashTok U_EXPORT2
+/*U_CAPI UHashTok U_EXPORT2
uhash_toki(int32_t i);*/
/**
* @param p The given pointer
* @return a UHashTok for a pointer.
*/
-/*U_CAPI UHashTok U_EXPORT2
+/*U_CAPI UHashTok U_EXPORT2
uhash_tokp(void* p);*/
/********************************************************************
* @param key The string (const UChar*) to hash.
* @return A hash code for the key.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_hashUChars(const UHashTok key);
/**
* @param key The string (const char*) to hash.
* @return A hash code for the key.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_hashChars(const UHashTok key);
/**
* @param key2 The string for comparison
* @return true if key1 and key2 are equal, return false otherwise.
*/
-U_CAPI UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
uhash_compareUChars(const UHashTok key1, const UHashTok key2);
/**
* @param key2 The string for comparison
* @return true if key1 and key2 are equal, return false otherwise.
*/
-U_CAPI UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
uhash_compareChars(const UHashTok key1, const UHashTok key2);
/**
* @param key2 The string for comparison
* @return true if key1 and key2 are equal, return false otherwise.
*/
-U_CAPI UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
uhash_compareIChars(const UHashTok key1, const UHashTok key2);
/********************************************************************
* @param key The string (const char*) to hash.
* @return A hash code for the key.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_hashUnicodeString(const UElement key);
/**
* @param key The string (const char*) to hash.
* @return A hash code for the key.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_hashCaselessUnicodeString(const UElement key);
/********************************************************************
* @param key The string (const char*) to hash.
* @return A hash code for the key.
*/
-U_CAPI int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
uhash_hashLong(const UHashTok key);
/**
* @param Key2 The integer for comparison
* @return true if key1 and key2 are equal, return false otherwise
*/
-U_CAPI UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
uhash_compareLong(const UHashTok key1, const UHashTok key2);
/********************************************************************
* Deleter for Hashtable objects.
* @param obj The object to be deleted
*/
-U_CAPI void U_EXPORT2
+U_CAPI void U_EXPORT2
uhash_deleteHashtable(void *obj);
/* Use uprv_free() itself as a deleter for any key or value allocated using uprv_malloc. */
* @param hash2
* @return true if the hashtables are equal and false if not.
*/
-U_CAPI UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
uhash_equals(const UHashtable* hash1, const UHashtable* hash2);
U_NAMESPACE_BEGIN
/**
- * \class LocalUResourceBundlePointer
- * "Smart pointer" class, closes a UResourceBundle via ures_close().
+ * \class LocalUHashtablePointer
+ * "Smart pointer" class, closes a UHashtable via uhash_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
U_NAMESPACE_END
-#endif
+#endif // U_SHOW_CPLUSPLUS_API
#endif