michael@0: /* michael@0: ****************************************************************************** michael@0: * Copyright (C) 1997-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ****************************************************************************** michael@0: * Date Name Description michael@0: * 03/22/00 aliu Adapted from original C++ ICU Hashtable. michael@0: * 07/06/01 aliu Modified to support int32_t keys on michael@0: * platforms with sizeof(void*) < 32. michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #ifndef UHASH_H michael@0: #define UHASH_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "cmemory.h" michael@0: #include "uelement.h" michael@0: michael@0: /** michael@0: * UHashtable stores key-value pairs and does moderately fast lookup michael@0: * based on keys. It provides a good tradeoff between access time and michael@0: * storage space. As elements are added to it, it grows to accomodate michael@0: * them. By default, the table never shrinks, even if all elements michael@0: * are removed from it. michael@0: * michael@0: * Keys and values are stored as void* pointers. These void* pointers michael@0: * may be actual pointers to strings, objects, or any other structure michael@0: * in memory, or they may simply be integral values cast to void*. michael@0: * UHashtable doesn't care and manipulates them via user-supplied michael@0: * functions. These functions hash keys, compare keys, delete keys, michael@0: * and delete values. Some function pointers are optional (may be michael@0: * NULL); others must be supplied. Several prebuilt functions exist michael@0: * to handle common key types. michael@0: * michael@0: * UHashtable ownership of keys and values is flexible, and controlled michael@0: * by whether or not the key deleter and value deleter functions are michael@0: * set. If a void* key is actually a pointer to a deletable object, michael@0: * then UHashtable can be made to delete that object by setting the michael@0: * key deleter function pointer to a non-NULL value. If this is done, michael@0: * then keys passed to uhash_put() are owned by the hashtable and will michael@0: * be deleted by it at some point, either as keys are replaced, or michael@0: * when uhash_close() is finally called. The same is true of values michael@0: * and the value deleter function pointer. Keys passed to methods michael@0: * other than uhash_put() are never owned by the hashtable. michael@0: * michael@0: * NULL values are not allowed. uhash_get() returns NULL to indicate michael@0: * a key that is not in the table, and having a NULL value in the michael@0: * table would generate an ambiguous result. If a key and a NULL michael@0: * value is passed to uhash_put(), this has the effect of doing a michael@0: * uhash_remove() on that key. This keeps uhash_get(), uhash_count(), michael@0: * and uhash_nextElement() consistent with one another. michael@0: * michael@0: * To see everything in a hashtable, use uhash_nextElement() to michael@0: * iterate through its contents. Each call to this function returns a michael@0: * UHashElement pointer. A hash element contains a key, value, and michael@0: * hashcode. During iteration an element may be deleted by calling michael@0: * uhash_removeElement(); iteration may safely continue thereafter. michael@0: * The uhash_remove() function may also be safely called in michael@0: * mid-iteration. However, if uhash_put() is called during iteration michael@0: * then the iteration will be out of sync. Under no circumstances michael@0: * should the UHashElement returned by uhash_nextElement be modified michael@0: * directly. michael@0: * michael@0: * By default, the hashtable grows when necessary, but never shrinks, michael@0: * even if all items are removed. For most applications this is michael@0: * optimal. However, in a highly dynamic usage where memory is at a michael@0: * premium, the table can be set to both grow and shrink by calling michael@0: * uhash_setResizePolicy() with the policy U_GROW_AND_SHRINK. In a michael@0: * situation where memory is critical and the client wants a table michael@0: * that does not grow at all, the constant U_FIXED can be used. michael@0: */ michael@0: michael@0: /******************************************************************** michael@0: * Data Structures michael@0: ********************************************************************/ michael@0: michael@0: U_CDECL_BEGIN michael@0: michael@0: /** michael@0: * A key or value within a UHashtable. michael@0: * The hashing and comparison functions take a pointer to a michael@0: * UHashTok, but the deleter receives the void* pointer within it. michael@0: */ michael@0: typedef UElement UHashTok; michael@0: michael@0: /** michael@0: * This is a single hash element. michael@0: */ michael@0: struct UHashElement { michael@0: /* Reorder these elements to pack nicely if necessary */ michael@0: int32_t hashcode; michael@0: UHashTok value; michael@0: UHashTok key; michael@0: }; michael@0: typedef struct UHashElement UHashElement; michael@0: michael@0: /** michael@0: * A hashing function. michael@0: * @param key A key stored in a hashtable michael@0: * @return A NON-NEGATIVE hash code for parm. michael@0: */ michael@0: typedef int32_t U_CALLCONV UHashFunction(const UHashTok key); michael@0: michael@0: /** michael@0: * A key equality (boolean) comparison function. michael@0: */ michael@0: typedef UElementsAreEqual UKeyComparator; michael@0: michael@0: /** michael@0: * A value equality (boolean) comparison function. michael@0: */ michael@0: typedef UElementsAreEqual UValueComparator; michael@0: michael@0: /* see cmemory.h for UObjectDeleter and uprv_deleteUObject() */ michael@0: michael@0: /** michael@0: * This specifies whether or not, and how, the hastable resizes itself. michael@0: * See uhash_setResizePolicy(). michael@0: */ michael@0: enum UHashResizePolicy { michael@0: U_GROW, /* Grow on demand, do not shrink */ michael@0: U_GROW_AND_SHRINK, /* Grow and shrink on demand */ michael@0: U_FIXED /* Never change size */ michael@0: }; michael@0: michael@0: /** michael@0: * The UHashtable struct. Clients should treat this as an opaque data michael@0: * type and manipulate it only through the uhash_... API. michael@0: */ michael@0: struct UHashtable { michael@0: michael@0: /* Main key-value pair storage array */ michael@0: michael@0: UHashElement *elements; michael@0: michael@0: /* Function pointers */ michael@0: michael@0: UHashFunction *keyHasher; /* Computes hash from key. michael@0: * Never null. */ michael@0: UKeyComparator *keyComparator; /* Compares keys for equality. michael@0: * Never null. */ michael@0: UValueComparator *valueComparator; /* Compares the values for equality */ michael@0: michael@0: UObjectDeleter *keyDeleter; /* Deletes keys when required. michael@0: * If NULL won't do anything */ michael@0: UObjectDeleter *valueDeleter; /* Deletes values when required. michael@0: * If NULL won't do anything */ michael@0: michael@0: /* Size parameters */ michael@0: michael@0: int32_t count; /* The number of key-value pairs in this table. michael@0: * 0 <= count <= length. In practice we michael@0: * never let count == length (see code). */ michael@0: int32_t length; /* The physical size of the arrays hashes, keys michael@0: * and values. Must be prime. */ michael@0: michael@0: /* Rehashing thresholds */ michael@0: michael@0: int32_t highWaterMark; /* If count > highWaterMark, rehash */ michael@0: int32_t lowWaterMark; /* If count < lowWaterMark, rehash */ michael@0: float highWaterRatio; /* 0..1; high water as a fraction of length */ michael@0: float lowWaterRatio; /* 0..1; low water as a fraction of length */ michael@0: michael@0: int8_t primeIndex; /* Index into our prime table for length. michael@0: * length == PRIMES[primeIndex] */ michael@0: UBool allocated; /* Was this UHashtable allocated? */ michael@0: }; michael@0: typedef struct UHashtable UHashtable; michael@0: michael@0: U_CDECL_END michael@0: michael@0: /******************************************************************** michael@0: * API michael@0: ********************************************************************/ michael@0: michael@0: /** michael@0: * Initialize a new UHashtable. michael@0: * @param keyHash A pointer to the key hashing function. Must not be michael@0: * NULL. michael@0: * @param keyComp A pointer to the function that compares keys. Must michael@0: * not be NULL. michael@0: * @param status A pointer to an UErrorCode to receive any errors. michael@0: * @return A pointer to a UHashtable, or 0 if an error occurred. michael@0: * @see uhash_openSize michael@0: */ michael@0: U_CAPI UHashtable* U_EXPORT2 michael@0: uhash_open(UHashFunction *keyHash, michael@0: UKeyComparator *keyComp, michael@0: UValueComparator *valueComp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Initialize a new UHashtable with a given initial size. michael@0: * @param keyHash A pointer to the key hashing function. Must not be michael@0: * NULL. michael@0: * @param keyComp A pointer to the function that compares keys. Must michael@0: * not be NULL. michael@0: * @param size The initial capacity of this hash table. michael@0: * @param status A pointer to an UErrorCode to receive any errors. michael@0: * @return A pointer to a UHashtable, or 0 if an error occurred. michael@0: * @see uhash_open michael@0: */ michael@0: U_CAPI UHashtable* U_EXPORT2 michael@0: uhash_openSize(UHashFunction *keyHash, michael@0: UKeyComparator *keyComp, michael@0: UValueComparator *valueComp, michael@0: int32_t size, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Initialize an existing UHashtable. michael@0: * @param keyHash A pointer to the key hashing function. Must not be michael@0: * NULL. michael@0: * @param keyComp A pointer to the function that compares keys. Must michael@0: * not be NULL. michael@0: * @param status A pointer to an UErrorCode to receive any errors. michael@0: * @return A pointer to a UHashtable, or 0 if an error occurred. michael@0: * @see uhash_openSize michael@0: */ michael@0: U_CAPI UHashtable* U_EXPORT2 michael@0: uhash_init(UHashtable *hash, michael@0: UHashFunction *keyHash, michael@0: UKeyComparator *keyComp, michael@0: UValueComparator *valueComp, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Close a UHashtable, releasing the memory used. michael@0: * @param hash The UHashtable to close. If hash is NULL no operation is performed. michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: uhash_close(UHashtable *hash); michael@0: michael@0: michael@0: michael@0: /** michael@0: * Set the function used to hash keys. michael@0: * @param hash The UHashtable to set michael@0: * @param fn the function to be used hash keys; must not be NULL michael@0: * @return the previous key hasher; non-NULL michael@0: */ michael@0: U_CAPI UHashFunction *U_EXPORT2 michael@0: uhash_setKeyHasher(UHashtable *hash, UHashFunction *fn); michael@0: michael@0: /** michael@0: * Set the function used to compare keys. The default comparison is a michael@0: * void* pointer comparison. michael@0: * @param hash The UHashtable to set michael@0: * @param fn the function to be used compare keys; must not be NULL michael@0: * @return the previous key comparator; non-NULL michael@0: */ michael@0: U_CAPI UKeyComparator *U_EXPORT2 michael@0: uhash_setKeyComparator(UHashtable *hash, UKeyComparator *fn); michael@0: michael@0: /** michael@0: * Set the function used to compare values. The default comparison is a michael@0: * void* pointer comparison. michael@0: * @param hash The UHashtable to set michael@0: * @param fn the function to be used compare keys; must not be NULL michael@0: * @return the previous key comparator; non-NULL michael@0: */ michael@0: U_CAPI UValueComparator *U_EXPORT2 michael@0: uhash_setValueComparator(UHashtable *hash, UValueComparator *fn); michael@0: michael@0: /** michael@0: * Set the function used to delete keys. If this function pointer is michael@0: * NULL, this hashtable does not delete keys. If it is non-NULL, this michael@0: * hashtable does delete keys. This function should be set once michael@0: * before any elements are added to the hashtable and should not be michael@0: * changed thereafter. michael@0: * @param hash The UHashtable to set michael@0: * @param fn the function to be used delete keys, or NULL michael@0: * @return the previous key deleter; may be NULL michael@0: */ michael@0: U_CAPI UObjectDeleter *U_EXPORT2 michael@0: uhash_setKeyDeleter(UHashtable *hash, UObjectDeleter *fn); michael@0: michael@0: /** michael@0: * Set the function used to delete values. If this function pointer michael@0: * is NULL, this hashtable does not delete values. If it is non-NULL, michael@0: * this hashtable does delete values. This function should be set michael@0: * once before any elements are added to the hashtable and should not michael@0: * be changed thereafter. michael@0: * @param hash The UHashtable to set michael@0: * @param fn the function to be used delete values, or NULL michael@0: * @return the previous value deleter; may be NULL michael@0: */ michael@0: U_CAPI UObjectDeleter *U_EXPORT2 michael@0: uhash_setValueDeleter(UHashtable *hash, UObjectDeleter *fn); michael@0: michael@0: /** michael@0: * Specify whether or not, and how, the hastable resizes itself. michael@0: * By default, tables grow but do not shrink (policy U_GROW). michael@0: * See enum UHashResizePolicy. michael@0: * @param hash The UHashtable to set michael@0: * @param policy The way the hashtable resizes itself, {U_GROW, U_GROW_AND_SHRINK, U_FIXED} michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: uhash_setResizePolicy(UHashtable *hash, enum UHashResizePolicy policy); michael@0: michael@0: /** michael@0: * Get the number of key-value pairs stored in a UHashtable. michael@0: * @param hash The UHashtable to query. michael@0: * @return The number of key-value pairs stored in hash. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_count(const UHashtable *hash); michael@0: michael@0: /** michael@0: * Put a (key=pointer, value=pointer) item in a UHashtable. If the michael@0: * keyDeleter is non-NULL, then the hashtable owns 'key' after this michael@0: * call. If the valueDeleter is non-NULL, then the hashtable owns michael@0: * 'value' after this call. Storing a NULL value is the same as michael@0: * calling uhash_remove(). michael@0: * @param hash The target UHashtable. michael@0: * @param key The key to store. michael@0: * @param value The value to store, may be NULL (see above). michael@0: * @param status A pointer to an UErrorCode to receive any errors. michael@0: * @return The previous value, or NULL if none. michael@0: * @see uhash_get michael@0: */ michael@0: U_CAPI void* U_EXPORT2 michael@0: uhash_put(UHashtable *hash, michael@0: void *key, michael@0: void *value, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Put a (key=integer, value=pointer) item in a UHashtable. michael@0: * keyDeleter must be NULL. If the valueDeleter is non-NULL, then the michael@0: * hashtable owns 'value' after this call. Storing a NULL value is michael@0: * the same as calling uhash_remove(). michael@0: * @param hash The target UHashtable. michael@0: * @param key The integer key to store. michael@0: * @param value The value to store, may be NULL (see above). michael@0: * @param status A pointer to an UErrorCode to receive any errors. michael@0: * @return The previous value, or NULL if none. michael@0: * @see uhash_get michael@0: */ michael@0: U_CAPI void* U_EXPORT2 michael@0: uhash_iput(UHashtable *hash, michael@0: int32_t key, michael@0: void* value, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Put a (key=pointer, value=integer) item in a UHashtable. If the michael@0: * keyDeleter is non-NULL, then the hashtable owns 'key' after this michael@0: * call. valueDeleter must be NULL. Storing a 0 value is the same as michael@0: * calling uhash_remove(). michael@0: * @param hash The target UHashtable. michael@0: * @param key The key to store. michael@0: * @param value The integer value to store. michael@0: * @param status A pointer to an UErrorCode to receive any errors. michael@0: * @return The previous value, or 0 if none. michael@0: * @see uhash_get michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_puti(UHashtable *hash, michael@0: void* key, michael@0: int32_t value, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Put a (key=integer, value=integer) item in a UHashtable. If the michael@0: * keyDeleter is non-NULL, then the hashtable owns 'key' after this michael@0: * call. valueDeleter must be NULL. Storing a 0 value is the same as michael@0: * calling uhash_remove(). michael@0: * @param hash The target UHashtable. michael@0: * @param key The key to store. michael@0: * @param value The integer value to store. michael@0: * @param status A pointer to an UErrorCode to receive any errors. michael@0: * @return The previous value, or 0 if none. michael@0: * @see uhash_get michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_iputi(UHashtable *hash, michael@0: int32_t key, michael@0: int32_t value, michael@0: UErrorCode *status); michael@0: michael@0: /** michael@0: * Retrieve a pointer value from a UHashtable using a pointer key, michael@0: * as previously stored by uhash_put(). michael@0: * @param hash The target UHashtable. michael@0: * @param key A pointer key stored in a hashtable michael@0: * @return The requested item, or NULL if not found. michael@0: */ michael@0: U_CAPI void* U_EXPORT2 michael@0: uhash_get(const UHashtable *hash, michael@0: const void *key); michael@0: michael@0: /** michael@0: * Retrieve a pointer value from a UHashtable using a integer key, michael@0: * as previously stored by uhash_iput(). michael@0: * @param hash The target UHashtable. michael@0: * @param key An integer key stored in a hashtable michael@0: * @return The requested item, or NULL if not found. michael@0: */ michael@0: U_CAPI void* U_EXPORT2 michael@0: uhash_iget(const UHashtable *hash, michael@0: int32_t key); michael@0: michael@0: /** michael@0: * Retrieve an integer value from a UHashtable using a pointer key, michael@0: * as previously stored by uhash_puti(). michael@0: * @param hash The target UHashtable. michael@0: * @param key A pointer key stored in a hashtable michael@0: * @return The requested item, or 0 if not found. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_geti(const UHashtable *hash, michael@0: const void* key); michael@0: /** michael@0: * Retrieve an integer value from a UHashtable using an integer key, michael@0: * as previously stored by uhash_iputi(). michael@0: * @param hash The target UHashtable. michael@0: * @param key An integer key stored in a hashtable michael@0: * @return The requested item, or 0 if not found. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_igeti(const UHashtable *hash, michael@0: int32_t key); michael@0: michael@0: /** michael@0: * Remove an item from a UHashtable stored by uhash_put(). michael@0: * @param hash The target UHashtable. michael@0: * @param key A key stored in a hashtable michael@0: * @return The item removed, or NULL if not found. michael@0: */ michael@0: U_CAPI void* U_EXPORT2 michael@0: uhash_remove(UHashtable *hash, michael@0: const void *key); michael@0: michael@0: /** michael@0: * Remove an item from a UHashtable stored by uhash_iput(). michael@0: * @param hash The target UHashtable. michael@0: * @param key An integer key stored in a hashtable michael@0: * @return The item removed, or NULL if not found. michael@0: */ michael@0: U_CAPI void* U_EXPORT2 michael@0: uhash_iremove(UHashtable *hash, michael@0: int32_t key); michael@0: michael@0: /** michael@0: * Remove an item from a UHashtable stored by uhash_puti(). michael@0: * @param hash The target UHashtable. michael@0: * @param key An key stored in a hashtable michael@0: * @return The item removed, or 0 if not found. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_removei(UHashtable *hash, michael@0: const void* key); michael@0: michael@0: /** michael@0: * Remove an item from a UHashtable stored by uhash_iputi(). michael@0: * @param hash The target UHashtable. michael@0: * @param key An integer key stored in a hashtable michael@0: * @return The item removed, or 0 if not found. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_iremovei(UHashtable *hash, michael@0: int32_t key); michael@0: michael@0: /** michael@0: * Remove all items from a UHashtable. michael@0: * @param hash The target UHashtable. michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: uhash_removeAll(UHashtable *hash); michael@0: michael@0: /** michael@0: * Locate an element of a UHashtable. The caller must not modify the michael@0: * returned object. The primary use of this function is to obtain the michael@0: * stored key when it may not be identical to the search key. For michael@0: * example, if the compare function is a case-insensitive string michael@0: * compare, then the hash key may be desired in order to obtain the michael@0: * canonical case corresponding to a search key. michael@0: * @param hash The target UHashtable. michael@0: * @param key A key stored in a hashtable michael@0: * @return a hash element, or NULL if the key is not found. michael@0: */ michael@0: U_CAPI const UHashElement* U_EXPORT2 michael@0: uhash_find(const UHashtable *hash, const void* key); michael@0: michael@0: /** michael@0: * Iterate through the elements of a UHashtable. The caller must not michael@0: * modify the returned object. However, uhash_removeElement() may be michael@0: * called during iteration to remove an element from the table. michael@0: * Iteration may safely be resumed afterwards. If uhash_put() is michael@0: * called during iteration the iteration will then be out of sync and michael@0: * should be restarted. michael@0: * @param hash The target UHashtable. michael@0: * @param pos This should be set to -1 initially, and left untouched michael@0: * thereafter. michael@0: * @return a hash element, or NULL if no further key-value pairs michael@0: * exist in the table. michael@0: */ michael@0: U_CAPI const UHashElement* U_EXPORT2 michael@0: uhash_nextElement(const UHashtable *hash, michael@0: int32_t *pos); michael@0: michael@0: /** michael@0: * Remove an element, returned by uhash_nextElement(), from the table. michael@0: * Iteration may be safely continued afterwards. michael@0: * @param hash The hashtable michael@0: * @param e The element, returned by uhash_nextElement(), to remove. michael@0: * Must not be NULL. Must not be an empty or deleted element (as long michael@0: * as this was returned by uhash_nextElement() it will not be empty or michael@0: * deleted). Note: Although this parameter is const, it will be michael@0: * modified. michael@0: * @return the value that was removed. michael@0: */ michael@0: U_CAPI void* U_EXPORT2 michael@0: uhash_removeElement(UHashtable *hash, const UHashElement* e); michael@0: michael@0: /******************************************************************** michael@0: * UHashTok convenience michael@0: ********************************************************************/ michael@0: michael@0: /** michael@0: * Return a UHashTok for an integer. michael@0: * @param i The given integer michael@0: * @return a UHashTok for an integer. michael@0: */ michael@0: /*U_CAPI UHashTok U_EXPORT2 michael@0: uhash_toki(int32_t i);*/ michael@0: michael@0: /** michael@0: * Return a UHashTok for a pointer. michael@0: * @param p The given pointer michael@0: * @return a UHashTok for a pointer. michael@0: */ michael@0: /*U_CAPI UHashTok U_EXPORT2 michael@0: uhash_tokp(void* p);*/ michael@0: michael@0: /******************************************************************** michael@0: * UChar* and char* Support Functions michael@0: ********************************************************************/ michael@0: michael@0: /** michael@0: * Generate a hash code for a null-terminated UChar* string. If the michael@0: * string is not null-terminated do not use this function. Use michael@0: * together with uhash_compareUChars. michael@0: * @param key The string (const UChar*) to hash. michael@0: * @return A hash code for the key. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_hashUChars(const UHashTok key); michael@0: michael@0: /** michael@0: * Generate a hash code for a null-terminated char* string. If the michael@0: * string is not null-terminated do not use this function. Use michael@0: * together with uhash_compareChars. michael@0: * @param key The string (const char*) to hash. michael@0: * @return A hash code for the key. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_hashChars(const UHashTok key); michael@0: michael@0: /** michael@0: * Generate a case-insensitive hash code for a null-terminated char* michael@0: * string. If the string is not null-terminated do not use this michael@0: * function. Use together with uhash_compareIChars. michael@0: * @param key The string (const char*) to hash. michael@0: * @return A hash code for the key. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_hashIChars(const UHashTok key); michael@0: michael@0: /** michael@0: * Comparator for null-terminated UChar* strings. Use together with michael@0: * uhash_hashUChars. michael@0: * @param key1 The string for comparison michael@0: * @param key2 The string for comparison michael@0: * @return true if key1 and key2 are equal, return false otherwise. michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uhash_compareUChars(const UHashTok key1, const UHashTok key2); michael@0: michael@0: /** michael@0: * Comparator for null-terminated char* strings. Use together with michael@0: * uhash_hashChars. michael@0: * @param key1 The string for comparison michael@0: * @param key2 The string for comparison michael@0: * @return true if key1 and key2 are equal, return false otherwise. michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uhash_compareChars(const UHashTok key1, const UHashTok key2); michael@0: michael@0: /** michael@0: * Case-insensitive comparator for null-terminated char* strings. Use michael@0: * together with uhash_hashIChars. michael@0: * @param key1 The string for comparison michael@0: * @param key2 The string for comparison michael@0: * @return true if key1 and key2 are equal, return false otherwise. michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uhash_compareIChars(const UHashTok key1, const UHashTok key2); michael@0: michael@0: /******************************************************************** michael@0: * UnicodeString Support Functions michael@0: ********************************************************************/ michael@0: michael@0: /** michael@0: * Hash function for UnicodeString* keys. michael@0: * @param key The string (const char*) to hash. michael@0: * @return A hash code for the key. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_hashUnicodeString(const UElement key); michael@0: michael@0: /** michael@0: * Hash function for UnicodeString* keys (case insensitive). michael@0: * Make sure to use together with uhash_compareCaselessUnicodeString. michael@0: * @param key The string (const char*) to hash. michael@0: * @return A hash code for the key. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_hashCaselessUnicodeString(const UElement key); michael@0: michael@0: /******************************************************************** michael@0: * int32_t Support Functions michael@0: ********************************************************************/ michael@0: michael@0: /** michael@0: * Hash function for 32-bit integer keys. michael@0: * @param key The string (const char*) to hash. michael@0: * @return A hash code for the key. michael@0: */ michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uhash_hashLong(const UHashTok key); michael@0: michael@0: /** michael@0: * Comparator function for 32-bit integer keys. michael@0: * @param key1 The integer for comparison michael@0: * @param Key2 The integer for comparison michael@0: * @return true if key1 and key2 are equal, return false otherwise michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uhash_compareLong(const UHashTok key1, const UHashTok key2); michael@0: michael@0: /******************************************************************** michael@0: * Other Support Functions michael@0: ********************************************************************/ michael@0: michael@0: /** michael@0: * Deleter for Hashtable objects. michael@0: * @param obj The object to be deleted michael@0: */ michael@0: U_CAPI void U_EXPORT2 michael@0: uhash_deleteHashtable(void *obj); michael@0: michael@0: /* Use uprv_free() itself as a deleter for any key or value allocated using uprv_malloc. */ michael@0: michael@0: /** michael@0: * Checks if the given hash tables are equal or not. michael@0: * @param hash1 michael@0: * @param hash2 michael@0: * @return true if the hashtables are equal and false if not. michael@0: */ michael@0: U_CAPI UBool U_EXPORT2 michael@0: uhash_equals(const UHashtable* hash1, const UHashtable* hash2); michael@0: michael@0: #endif