psHash.h

Go to the documentation of this file.
00001 /** @file  psHash.h
00002  *
00003  *  @brief Contains support for basic hashing functions.
00004  *
00005  *  This file will hold the prototypes for defining a hash table with arbitrary
00006  *  data types, allocating/deallocating that has table, adding and removing
00007  *  data from that hash table, and listing all keys defined in the hash table.
00008  *
00009  *  @author Robert Lupton, Princeton University
00010  *  @author Robert DeSonia, MHPCC
00011  *  @author GLG, MHPCC
00012  *
00013  *  @version $Revision: 1.20 $ $Name:  $
00014  *  @date $Date: 2007/01/23 22:47:23 $
00015  *
00016  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00017  */
00018 
00019 #ifndef PS_HASH_H
00020 #define PS_HASH_H
00021 
00022 /// @addtogroup DataContainer Data Containers
00023 /// @{
00024 
00025 #include "psList.h"
00026 
00027 /** A bucket that holds an item of data. */
00028 typedef struct psHashBucket
00029 {
00030     char *key;                         ///< The key for this item of data.
00031     psPtr data;                        ///< The data itself.
00032     struct psHashBucket* next;         ///< The list of other possible keys.
00033 }
00034 psHashBucket;
00035 
00036 //typedef struct HashTable psHash; ///< Opaque type for a hash table
00037 
00038 /** The hash-table itself. */
00039 typedef struct
00040 {
00041     long n;                            ///< Number of buckets in hash table.
00042     psHashBucket* *buckets;            ///< The bucket data.
00043     void *lock;                        ///< Optional lock for thread safety.
00044 }
00045 psHash;
00046 
00047 /** Checks the type of a particular pointer.
00048  *
00049  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00050  *
00051  *  @return bool:       True if the pointer matches a psHash structure, false otherwise.
00052  */
00053 bool psMemCheckHash(
00054     psPtr ptr                          ///< the pointer whose type to check
00055 )
00056 ;
00057 
00058 /// Allocate hash buckets in table.
00059 psHash* psHashAlloc(
00060     long nalloc                        ///< The number of buckets to allocate.
00061 );
00062 
00063 /// Insert entry into table.
00064 bool psHashAdd(
00065     psHash* hash,                      ///< The table to insert in.
00066     const char *key,                   ///< The key to use.
00067     psPtr data                         ///< The data to insert.
00068 );
00069 
00070 /// Lookup key in table.
00071 psPtr psHashLookup(
00072     const psHash* hash,                ///< The table to lookup key in.
00073     const char *key                    ///< The key to lookup.
00074 );
00075 
00076 /// Remove key from table.
00077 bool psHashRemove(
00078     psHash* hash,                      ///< The table to lookup key in.
00079     const char *key                    ///< The key to lookup.
00080 );
00081 
00082 /// List all keys in table.
00083 psList* psHashKeyList(
00084     const psHash* hash                 ///< The table to list keys from..
00085 );
00086 
00087 /** Create a psArray from a psHash contents.
00088  *
00089  *  @return psArray*       A new psArray with duplicate contents of the input psHash
00090  */
00091 psArray* psHashToArray(
00092     const psHash* hash                 ///< The table to convert to psArray.
00093 );
00094 
00095 /// @} End of DataContainer Functions
00096 #endif // #ifndef PS_HASH_H

Generated on Fri Feb 2 22:24:35 2007 for pslib by  doxygen 1.5.1