
/** @file  psHash.h
 *  @brief Contains support for basic hashing functions.
 *  @ingroup HashTable
 *
 *  This file will hold the prototypes for defining a hash table with arbitrary
 *  data types, allocating/deallocating that has table, adding and removing
 *  data from that hash table, and listing all keys defined in the hash table.
 *
 *  @author Robert Lupton, Princeton University
 *  @author George Gusciora, MHPCC
 *   
 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2004-08-09 23:40:55 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 */
#if !defined(PS_HASH_H)
#define PS_HASH_H

/** \addtogroup HashTable
 *  \{
 */
#include<stdbool.h>

#include "psList.h"

/** A bucket that holds an item of data. */
typedef struct psHashBucket
{
    char *key;                  ///< key for this item of data
    void *data;                 ///< the data itself
    struct psHashBucket* next;  ///< list of other possible keys
}
psHashBucket;

//typedef struct HashTable psHash; ///< Opaque type for a hash table

/** The hash-table itself. */
typedef struct psHash
{
    int nbucket;                ///< Number of buckets in hash table.
    psHashBucket* *buckets;     ///< The bucket data.
}
psHash;

/// Allocate hash buckets in table.
psHash* psHashAlloc(int nbucket ///< The number of buckets to allocate.
                   );

/// Insert entry into table.
bool psHashAdd(psHash* table,  ///< table to insert in
               const char *key, ///< key to use
               void *data       ///< data to insert
              );

/// Lookup key in table.
void *psHashLookup(psHash* table,      ///< table to lookup key in
                   const char *key      ///< key to lookup
                  );

/// Remove key from table.
bool psHashRemove(psHash* table,       ///< table to lookup key in
                  const char *key       ///< key to lookup
                 );

/// List all keys in table.
psList* psHashKeyList(psHash* table    ///< table to list keys from.
                     );

/* \} */// End of DataGroup Functions

#endif
