Index: /trunk/psLib/src/types/psHash.c
===================================================================
--- /trunk/psLib/src/types/psHash.c	(revision 9082)
+++ /trunk/psLib/src/types/psHash.c	(revision 9083)
@@ -12,6 +12,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-09-26 02:55:34 $
+*  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-01 00:45:34 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -47,11 +47,9 @@
 psList* psHashKeyList(const psHash* hash)
 {
+    PS_ASSERT_PTR_NON_NULL(hash, NULL);
     psS32 i = 0;                  // Loop index variable
     psList* myLinkList = NULL;  // The output data structure
     psHashBucket* ptr = NULL;   // Used to step thru linked list.
 
-    if (hash == NULL) {
-        return NULL;
-    }
     // Create the linked list
     myLinkList = psListAlloc(NULL);
@@ -98,10 +96,12 @@
     bucket->key = psStringCopy(key);
 
-    if (data == NULL) {
-        // NOTE: Should we flag a warning message?
-        bucket->data = NULL;
-    } else {
-        bucket->data = psMemIncrRefCounter(data);
-    }
+    //XXX:  Since this function is static and only called by doHashWork,
+    //data can never be NULL here.
+    //    if (data == NULL) {
+    // NOTE: Should we flag a warning message?
+    //        bucket->data = NULL;
+    //    } else {
+    bucket->data = psMemIncrRefCounter(data);
+    //    }
 
     bucket->next = next;
@@ -120,10 +120,5 @@
 static void hashBucketFree(psHashBucket* bucket)
 {
-    if (bucket == NULL) {
-        return;
-    }
-
     psFree(bucket->key);
-
     psFree(bucket->data);
 }
@@ -139,4 +134,10 @@
 psHash* psHashAlloc(long nalloc)        // initial number of buckets
 {
+    if (nalloc < 0)
+    {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "Can't allocate a psHash of negative size.");
+        return NULL;
+    }
     psS32 i = 0;                  // loop index variable
 
@@ -185,7 +186,4 @@
     psS32 i = 0;                  // Loop index variable.
 
-    if (table == NULL) {
-        return;
-    }
     // Loop through each bucket in the hash table.  If that bucket is not
     // NULL, then free the bucket via a function call to hashBucketFree();
@@ -225,5 +223,6 @@
 static psPtr doHashWork(psHash* table,
                         const char *key,
-                        psPtr data, psBool remove
+                        psPtr data,
+                        psBool remove
                            )
 {
@@ -240,9 +239,10 @@
     // function, but I'm checking it anyway since future coders might change
     // the way this procedure is called.
-    if ((table == NULL) || (key == NULL)) {
+    /*    if ((table == NULL) || (key == NULL)) {
         psError(PS_ERR_BAD_PARAMETER_NULL, true,
-                _("Input key can not be NULL."));
+        _("Input key can not be NULL."));
         return NULL;
     }
+    */
     // NOTE: This is the originally supplied hash function.
     // for (psS32 i = 0, len = strlen(key); i < len; i++) {
@@ -253,4 +253,6 @@
     // This hash algorithm is from Sedgewick.  NOTE: must reread to ensure that
     // the size of the hash table is not required to be a prime number.
+    if (table->n <= 0)
+        return NULL;
     tmpchar = (char *)key;
     for (hash = 0; *tmpchar != '\0'; tmpchar++) {
@@ -260,8 +262,9 @@
     // NOTE: This should not be necessary, but for now, I'm checking bounds
     // anyway.
-    if ((hash < 0) || (hash >= table->n)) {
+    /*    if ((hash < 0) || (hash >= table->n)) {
         psError(PS_ERR_UNKNOWN, true,
-                "Internal hash function out of range (%" PRId64 ")", hash);
-    }
+        "Internal hash function out of range (%" PRId64 ")", hash);
+    }
+    */
     // ptr will have the correct hash bucket.
     ptr = table->buckets[hash];
@@ -397,9 +400,9 @@
                   const char *key)
 {
+    PS_ASSERT_PTR_NON_NULL(hash, false);
+    PS_ASSERT_PTR_NON_NULL(key, false);
+
     psPtr data = NULL;
     psBool retVal = false;
-
-    PS_ASSERT_PTR_NON_NULL(hash, false);
-    PS_ASSERT_PTR_NON_NULL(key, false);
 
     data = doHashWork(hash, key, NULL, true);
@@ -421,4 +424,6 @@
     int nElements = 0;
     int nbucket = hash->n;
+    //XXX:  If we do psArrayAlloc(0) here and use psArrayAdd(result, 1, tmpBucket->data)
+    //we can eliminate the 2nd for loop below.
     for (int i = 0; i < nbucket; i++) {
         psHashBucket* tmpBucket = hash->buckets[i];
Index: /trunk/psLib/src/types/psHash.h
===================================================================
--- /trunk/psLib/src/types/psHash.h	(revision 9082)
+++ /trunk/psLib/src/types/psHash.h	(revision 9083)
@@ -11,6 +11,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-09-26 02:55:34 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-01 00:45:34 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
