Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psHash.h

Go to the documentation of this file.
00001 /** @file  psHash.h
00002  *  @brief Contains support for basic hashing functions.
00003  *  @ingroup HashTable
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.1.1.1 $ $Name:  $
00014  *  @date $Date: 2005/09/14 20:42:48 $
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 HashTable
00023  *  \{
00024  */
00025 
00026 #include "psList.h"
00027 
00028 /** A bucket that holds an item of data. */
00029 typedef struct psHashBucket
00030 {
00031     char *key;                         ///< The key for this item of data.
00032     psPtr data;                        ///< The data itself.
00033     struct psHashBucket* next;         ///< The list of other possible keys.
00034 }
00035 psHashBucket;
00036 
00037 //typedef struct HashTable psHash; ///< Opaque type for a hash table
00038 
00039 /** The hash-table itself. */
00040 typedef struct
00041 {
00042     long n;                            ///< Number of buckets in hash table.
00043     psHashBucket* *buckets;            ///< The bucket data.
00044     void *lock;                        ///< Optional lock for thread safety.
00045 }
00046 psHash;
00047 
00048 /** Checks the type of a particular pointer.
00049  *
00050  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00051  *
00052  *  @return bool:       True if the pointer matches a psHash structure, false otherwise.
00053  */
00054 bool psMemCheckHash(
00055     psPtr ptr                          ///< the pointer whose type to check
00056 )
00057 ;
00058 
00059 
00060 /// Allocate hash buckets in table.
00061 psHash* psHashAlloc(
00062     long nalloc                        ///< The number of buckets to allocate.
00063 );
00064 
00065 /// Insert entry into table.
00066 bool psHashAdd(
00067     psHash* hash,                      ///< The table to insert in.
00068     const char *key,                   ///< The key to use.
00069     psPtr data                         ///< The data to insert.
00070 );
00071 
00072 /// Lookup key in table.
00073 psPtr psHashLookup(
00074     const psHash* hash,                ///< The table to lookup key in.
00075     const char *key                    ///< The key to lookup.
00076 );
00077 
00078 /// Remove key from table.
00079 bool psHashRemove(
00080     psHash* hash,                      ///< The table to lookup key in.
00081     const char *key                    ///< The key to lookup.
00082 );
00083 
00084 /// List all keys in table.
00085 psList* psHashKeyList(
00086     const psHash* hash                 ///< The table to list keys from..
00087 );
00088 
00089 /** Create a psArray from a psHash contents.
00090  *
00091  *  @return psArray*       A new psArray with duplicate contents of the input psHash
00092  */
00093 psArray* psHashToArray(
00094     const psHash* hash                 ///< The table to convert to psArray.
00095 );
00096 
00097 /* \} */// End of DataGroup Functions
00098 
00099 #endif // #ifndef PS_HASH_H

Generated on Wed Sep 14 10:42:48 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2