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