Index: trunk/psLib/src/sysUtils/psHash.c
===================================================================
--- trunk/psLib/src/sysUtils/psHash.c	(revision 964)
+++ trunk/psLib/src/sysUtils/psHash.c	(revision 1073)
@@ -10,6 +10,6 @@
  *  @author George Gusciora, MHPCC
  *   
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-10 00:09:55 $
+ *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-23 23:00:15 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,5 @@
 #include <stdio.h>
 #include <string.h>
+#include <stdbool.h>
 #include "psHash.h"
 #include "psMemory.h"
@@ -24,4 +25,9 @@
 #include "psAbort.h"
 
+static psHashBucket *hashBucketAlloc(const char *key,void *data,psHashBucket *next);
+static void hashBucketFree(psHashBucket *bucket);
+static void *doHashWork(psHash* table, const char* key, void* data, bool remove
+                           );
+static void hashFree(psHash *table);
 
 /******************************************************************************
@@ -87,4 +93,5 @@
     // Allocate memory for the new hash bucket.
     psHashBucket *bucket = psAlloc(sizeof(psHashBucket));
+    p_psMemSetDeallocator(bucket,(psFreeFcn)hashBucketFree);
 
     // Initialize the bucket.
@@ -105,20 +112,14 @@
 
 /******************************************************************************
-hashBucketFree(bucket, itemFree): This procedure deallocates the specified
-hash bucket.  If "itemFree" is NULL, then we simply free the data with the
-standard psFree() function.  If "itemFree" is not NULL, then it must be a
-function pointer which takes the hash bucket as a parameter, and frees the
-data in that hash bucket.
+hashBucketFree(bucket): This procedure deallocates the specified
+hash bucket.  
 Inputs:
     bucket: the hash bucket to be freed.
-    itemFree: a function pointer, possibly NULL.
 Return:
     NONE
  *****************************************************************************/
-static void hashBucketFree(psHashBucket *bucket,   // bucket to free
-                           void (*itemFree)(void *item)) // how to free data;
-{
-    if (bucket == NULL)
-    {
+static void hashBucketFree(psHashBucket *bucket)
+{
+    if (bucket == NULL) {
         return;
     }
@@ -126,21 +127,9 @@
     // A bucket is actually a linked list of buckets.  We recursively step
     // through that linked list, free each bucket.
-    if (bucket->next != NULL)
-    {
-        hashBucketFree(bucket, itemFree);
-    }
+    psFree(bucket->next);
 
     psFree(bucket->key);
-    psMemDecrRefCounter(bucket->data);
-
-    if (itemFree != NULL)
-    {
-        itemFree(bucket->data);
-    } else
-    {
-        psFree(bucket->data);
-    }
-
-    psFree(bucket);
+
+    psFree(bucket->data);
 }
 
@@ -159,4 +148,5 @@
     // Create the new hash table.
     psHash *table = psAlloc(sizeof(psHash));
+    p_psMemSetDeallocator(table,(psFreeFcn)hashFree);
 
     // Allocate memory for the buckets.
@@ -185,10 +175,8 @@
 Inputs:
     table: a hash table
-    itemFree: a function pointer, possibly NULL.
 Return:
     NONE
  *****************************************************************************/
-void psHashFree(psHash *table,  // hash table to be freed
-                void (*itemFree)(void *item)) // how to free hashed data; or NULL
+static void hashFree(psHash *table)
 {
     psHashBucket *tmp = NULL;           // Used to step through linked list.
@@ -196,6 +184,5 @@
     int i = 0;                          // Loop index variable.
 
-    if (table == NULL)
-    {
+    if (table == NULL) {
         return;
     }
@@ -204,6 +191,5 @@
     // NULL, then free the bucket via a function call to hashBucketFree();
 
-    for (i = 0; i < table->nbucket; i++)
-    {
+    for (i = 0; i < table->nbucket; i++) {
         // A bucket is composed of a linked list of buckets.  We use the
         // "tmp" and "ptr" pointers to step through that list and free each
@@ -214,5 +200,5 @@
             while (ptr != NULL) {
                 tmp = ptr->next;
-                hashBucketFree(ptr, itemFree);
+                psFree(ptr);
                 ptr = tmp;
             }
@@ -222,15 +208,13 @@
     // Free the bucket structure, then the hash table.
     psFree(table->buckets);
-    psFree(table);
-}
-
-/******************************************************************************
-doHashWork(table, key, data, remove, itemFree): This is an internal
+}
+
+/******************************************************************************
+doHashWork(table, key, data, remove): This is an internal
 procedure which does the bulk of the work in using the hash table.  Depending
 upon the input parameters, it will either insert a new key/data into the hash
 table, retrieve the data for a specified key, or remove a key/data item.  If
-we try to insert a key that already exists in the hash table, then we call
-the user-supplied function itemfree (or psFree if that is NULL), to free the
-existing data/key item.
+we try to insert a key that already exists in the hash table, then we deallocate
+the existing data/key item.
 Inputs:
     table: a hash table
@@ -238,5 +222,4 @@
     data: the data to insert, if not NULL
     remove: set to non-zero if the key/data should be removed from the table.
-    itemFree: function pointer
 Return:
     NONE
@@ -246,10 +229,6 @@
 there is little common code between those functions.
   *****************************************************************************/
-static void *doHashWork(psHash     *table,   // table to insert in
-                        const char *key,     // key to use
-                        void       *data,    // data to insert, or (if NULL) retrieve/remove
-                        int remove
-                            ,          // remove the item from the list?
-                            void (*itemFree)(void *item)) // how to free hashed data
+static void *doHashWork(psHash *table, const char *key, void *data, bool remove
+                           )
 {
     long int hash = 1;                  // This will contain an integer value
@@ -313,10 +292,9 @@
                     }
 
-                    psFree(ptr->key);
                     psFree(ptr);
 
                     // By definition, the data associated with that key
                     // must be returned, not freed.
-                    return psMemDecrRefCounter(data);
+                    return data;
                 }
                 optr = ptr;
@@ -354,9 +332,5 @@
                 // the new data was not inserted into the hash table.
 
-                if (itemFree == NULL) {
-                    psFree(psMemDecrRefCounter(ptr->data));
-                } else {
-                    itemFree(psMemDecrRefCounter(ptr->data));
-                }
+                psFree(ptr->data);
 
                 ptr->data = psMemIncrRefCounter(data);
@@ -385,8 +359,5 @@
     NONE
  *****************************************************************************/
-void *psHashInsert(psHash *table,   // table to insert in
-                   const char *key, // key to use
-                   void *data,      // data to insert
-                   void (*itemFree)(void *item)) // how to free hashed data;
+void *psHashInsert(psHash *table, const char *key, void *data)
 {
     if (table == NULL) {
@@ -400,5 +371,5 @@
     }
 
-    return doHashWork(table, key, data, 0, itemFree);
+    return doHashWork(table, key, data, 0);
 }
 
@@ -425,5 +396,5 @@
 
 
-    return doHashWork(table, key, NULL, 0, NULL);
+    return doHashWork(table, key, NULL, 0);
 }
 
@@ -438,7 +409,5 @@
     The data that was associated with that key.
  *****************************************************************************/
-void *psHashRemove(psHash *table,   // table to lookup key in
-                   const char *key, // key to lookup
-                   void (*itemFree)(void *item)) // how to free hashed data;
+void *psHashRemove(psHash *table, const char *key)
 {
     if (table == NULL) {
@@ -449,4 +418,4 @@
     }
 
-    return doHashWork(table, key, NULL, 1, itemFree);
-}
+    return doHashWork(table, key, NULL, 1);
+}
