Index: /trunk/psLib/psLib.kdevses
===================================================================
--- /trunk/psLib/psLib.kdevses	(revision 2858)
+++ /trunk/psLib/psLib.kdevses	(revision 2859)
@@ -2,14 +2,20 @@
 <!DOCTYPE KDevPrjSession>
 <KDevPrjSession>
- <DocsAndViews NumberOfDocuments="3" >
-  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/astronomy/psAstrometry.c" >
-   <View0 Type="Source" />
+ <DocsAndViews NumberOfDocuments="5" >
+  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psHash.c" >
+   <View0 line="451" Type="Source" />
   </Doc0>
-  <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/test/astronomy/tst_psAstrometry.c" >
-   <View0 Type="Source" />
+  <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psHash.h" >
+   <View0 line="42" Type="Source" />
   </Doc1>
   <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psArray.c" >
-   <View0 line="91" Type="Source" />
+   <View0 line="0" Type="Source" />
   </Doc2>
+  <Doc3 NumberOfViews="1" URL="file:/home/desonia/psLib/test/collections/tst_psHash04.c" >
+   <View0 line="0" Type="Source" />
+  </Doc3>
+  <Doc4 NumberOfViews="1" URL="file:/home/desonia/psLib/test/collections/tst_psHash05.c" >
+   <View0 line="31" Type="Source" />
+  </Doc4>
  </DocsAndViews>
  <pluginList>
Index: /trunk/psLib/src/collections/psHash.c
===================================================================
--- /trunk/psLib/src/collections/psHash.c	(revision 2858)
+++ /trunk/psLib/src/collections/psHash.c	(revision 2859)
@@ -10,7 +10,8 @@
 *  @author Robert Lupton, Princeton University
 *  @author George Gusciora, MHPCC
+*  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-12-04 02:43:39 $
+*  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-03 20:28:07 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -361,5 +362,5 @@
     }
 
-    return (doHashWork(table, key, data, 0) != NULL);
+    return (doHashWork(table, key, data, false) != NULL);
 }
 
@@ -389,5 +390,5 @@
     }
 
-    return doHashWork(table, key, NULL, 0);
+    return doHashWork(table, key, NULL, false);
 }
 
@@ -418,5 +419,5 @@
     }
 
-    data = doHashWork(table, key, NULL, 1);
+    data = doHashWork(table, key, NULL, true);
     if (data != NULL) {
         retVal = true;
@@ -427,2 +428,39 @@
     return retVal;
 }
+
+psArray* psHashToArray(psHash* table)
+{
+
+    if (table == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                PS_ERRORTEXT_psHash_TABLE_NULL);
+        return NULL;
+    }
+
+    // first, let's just count the number of data elements to know what size
+    // psArray we need to allocate.
+    int nElements = 0;
+    int nbucket = table->nbucket;
+    for (int i = 0; i < nbucket; i++) {
+        psHashBucket* tmpBucket = table->buckets[i];
+        while (tmpBucket != NULL) {
+            nElements++;
+            tmpBucket = tmpBucket->next;
+        }
+    }
+
+    psArray* result = psArrayAlloc(nElements);
+    result->n = nElements;
+
+    // now fill in the array with the hash table's data
+    psPtr* data = result->data;
+    for (int i = 0; i < nbucket; i++) {
+        psHashBucket* tmpBucket = table->buckets[i];
+        while (tmpBucket != NULL) {
+            *(data++) = psMemIncrRefCounter(tmpBucket->data);
+            tmpBucket = tmpBucket->next;
+        }
+    }
+
+    return result;
+}
Index: /trunk/psLib/src/collections/psHash.h
===================================================================
--- /trunk/psLib/src/collections/psHash.h	(revision 2858)
+++ /trunk/psLib/src/collections/psHash.h	(revision 2859)
@@ -10,7 +10,8 @@
  *  @author Robert Lupton, Princeton University
  *  @author George Gusciora, MHPCC
- *   
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-27 00:57:31 $
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-01-03 20:28:07 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,7 +29,7 @@
 typedef struct psHashBucket
 {
-    char *key;                  ///< key for this item of data
-    psPtr data;                 ///< the data itself
-    struct psHashBucket* next;  ///< list of other possible keys
+    char *key;                         ///< key for this item of data
+    psPtr data;                        ///< the data itself
+    struct psHashBucket* next;         ///< list of other possible keys
 }
 psHashBucket;
@@ -39,32 +40,45 @@
 typedef struct psHash
 {
-    psS32 nbucket;                ///< Number of buckets in hash table.
-    psHashBucket* *buckets;     ///< The bucket data.
+    psS32 nbucket;                     ///< Number of buckets in hash table.
+    psHashBucket* *buckets;            ///< The bucket data.
 }
 psHash;
 
 /// Allocate hash buckets in table.
-psHash* psHashAlloc(psS32 nbucket ///< The number of buckets to allocate.
-                   );
+psHash* psHashAlloc(
+    psS32 nbucket                  ///< The number of buckets to allocate.
+);
 
 /// Insert entry into table.
-psBool psHashAdd(psHash* table,  ///< table to insert in
-                 const char *key, ///< key to use
-                 psPtr data       ///< data to insert
-                );
+psBool psHashAdd(
+    psHash* table,                 ///< table to insert in
+    const char *key,               ///< key to use
+    psPtr data                     ///< data to insert
+);
 
 /// Lookup key in table.
-psPtr psHashLookup(psHash* table,      ///< table to lookup key in
-                   const char *key      ///< key to lookup
-                  );
+psPtr psHashLookup(
+    psHash* table,                 ///< table to lookup key in
+    const char *key                ///< key to lookup
+);
 
 /// Remove key from table.
-psBool psHashRemove(psHash* table,       ///< table to lookup key in
-                    const char *key       ///< key to lookup
-                   );
+psBool 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.
-                     );
+psList* psHashKeyList(
+    psHash* table                  ///< table to list keys from.
+);
+
+/** Create a psArray from a psHash contents.
+ *
+ *  @return psArray*       A new psArray with duplicate contents of the input psHash
+ */
+psArray* psHashToArray(
+    psHash* table                  ///< table to convert to psArray
+);
 
 /* \} */// End of DataGroup Functions
Index: /trunk/psLib/src/types/psHash.c
===================================================================
--- /trunk/psLib/src/types/psHash.c	(revision 2858)
+++ /trunk/psLib/src/types/psHash.c	(revision 2859)
@@ -10,7 +10,8 @@
 *  @author Robert Lupton, Princeton University
 *  @author George Gusciora, MHPCC
+*  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-12-04 02:43:39 $
+*  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-03 20:28:07 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -361,5 +362,5 @@
     }
 
-    return (doHashWork(table, key, data, 0) != NULL);
+    return (doHashWork(table, key, data, false) != NULL);
 }
 
@@ -389,5 +390,5 @@
     }
 
-    return doHashWork(table, key, NULL, 0);
+    return doHashWork(table, key, NULL, false);
 }
 
@@ -418,5 +419,5 @@
     }
 
-    data = doHashWork(table, key, NULL, 1);
+    data = doHashWork(table, key, NULL, true);
     if (data != NULL) {
         retVal = true;
@@ -427,2 +428,39 @@
     return retVal;
 }
+
+psArray* psHashToArray(psHash* table)
+{
+
+    if (table == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                PS_ERRORTEXT_psHash_TABLE_NULL);
+        return NULL;
+    }
+
+    // first, let's just count the number of data elements to know what size
+    // psArray we need to allocate.
+    int nElements = 0;
+    int nbucket = table->nbucket;
+    for (int i = 0; i < nbucket; i++) {
+        psHashBucket* tmpBucket = table->buckets[i];
+        while (tmpBucket != NULL) {
+            nElements++;
+            tmpBucket = tmpBucket->next;
+        }
+    }
+
+    psArray* result = psArrayAlloc(nElements);
+    result->n = nElements;
+
+    // now fill in the array with the hash table's data
+    psPtr* data = result->data;
+    for (int i = 0; i < nbucket; i++) {
+        psHashBucket* tmpBucket = table->buckets[i];
+        while (tmpBucket != NULL) {
+            *(data++) = psMemIncrRefCounter(tmpBucket->data);
+            tmpBucket = tmpBucket->next;
+        }
+    }
+
+    return result;
+}
Index: /trunk/psLib/src/types/psHash.h
===================================================================
--- /trunk/psLib/src/types/psHash.h	(revision 2858)
+++ /trunk/psLib/src/types/psHash.h	(revision 2859)
@@ -10,7 +10,8 @@
  *  @author Robert Lupton, Princeton University
  *  @author George Gusciora, MHPCC
- *   
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-27 00:57:31 $
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-01-03 20:28:07 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,7 +29,7 @@
 typedef struct psHashBucket
 {
-    char *key;                  ///< key for this item of data
-    psPtr data;                 ///< the data itself
-    struct psHashBucket* next;  ///< list of other possible keys
+    char *key;                         ///< key for this item of data
+    psPtr data;                        ///< the data itself
+    struct psHashBucket* next;         ///< list of other possible keys
 }
 psHashBucket;
@@ -39,32 +40,45 @@
 typedef struct psHash
 {
-    psS32 nbucket;                ///< Number of buckets in hash table.
-    psHashBucket* *buckets;     ///< The bucket data.
+    psS32 nbucket;                     ///< Number of buckets in hash table.
+    psHashBucket* *buckets;            ///< The bucket data.
 }
 psHash;
 
 /// Allocate hash buckets in table.
-psHash* psHashAlloc(psS32 nbucket ///< The number of buckets to allocate.
-                   );
+psHash* psHashAlloc(
+    psS32 nbucket                  ///< The number of buckets to allocate.
+);
 
 /// Insert entry into table.
-psBool psHashAdd(psHash* table,  ///< table to insert in
-                 const char *key, ///< key to use
-                 psPtr data       ///< data to insert
-                );
+psBool psHashAdd(
+    psHash* table,                 ///< table to insert in
+    const char *key,               ///< key to use
+    psPtr data                     ///< data to insert
+);
 
 /// Lookup key in table.
-psPtr psHashLookup(psHash* table,      ///< table to lookup key in
-                   const char *key      ///< key to lookup
-                  );
+psPtr psHashLookup(
+    psHash* table,                 ///< table to lookup key in
+    const char *key                ///< key to lookup
+);
 
 /// Remove key from table.
-psBool psHashRemove(psHash* table,       ///< table to lookup key in
-                    const char *key       ///< key to lookup
-                   );
+psBool 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.
-                     );
+psList* psHashKeyList(
+    psHash* table                  ///< table to list keys from.
+);
+
+/** Create a psArray from a psHash contents.
+ *
+ *  @return psArray*       A new psArray with duplicate contents of the input psHash
+ */
+psArray* psHashToArray(
+    psHash* table                  ///< table to convert to psArray
+);
 
 /* \} */// End of DataGroup Functions
Index: /trunk/psLib/test/collections/Makefile
===================================================================
--- /trunk/psLib/test/collections/Makefile	(revision 2858)
+++ /trunk/psLib/test/collections/Makefile	(revision 2859)
@@ -3,6 +3,6 @@
 ##  Makefile:   test/collections
 ##
-##  $Revision: 1.26 $  $Name: not supported by cvs2svn $
-##  $Date: 2004-12-27 21:12:47 $
+##  $Revision: 1.27 $  $Name: not supported by cvs2svn $
+##  $Date: 2005-01-03 20:28:07 $
 ##
 ##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -34,4 +34,5 @@
          tst_psHash03          \
          tst_psHash04          \
+         tst_psHash05          \
          tst_psScalar
 
Index: /trunk/psLib/test/collections/tst_psHash05.c
===================================================================
--- /trunk/psLib/test/collections/tst_psHash05.c	(revision 2859)
+++ /trunk/psLib/test/collections/tst_psHash05.c	(revision 2859)
@@ -0,0 +1,172 @@
+/** @file  tst_psHash05.c
+*
+*  @brief Contains the tests for psHash.[ch]
+*
+*
+*  @author Robert DeSonia, MHPCC
+*
+*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-01-03 20:28:07 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
+
+#include "psTest.h"
+#include "pslib.h"
+
+static psS32 hashToArray( void );
+
+testDescription tests[] = {
+                              {hashToArray, 789, "psHashToArray", 0, false},
+                              {NULL}
+                          };
+
+static void printIntArray(char* name, psArray* arr)
+{
+    if (arr == NULL) {
+        printf("%s = NULL\n",name);
+        return;
+    }
+
+    printf("%s = {",name);
+    for (int i = 0; i < arr->n; i++) {
+        if (arr->data[i] == NULL) {
+            printf("NULL");
+        } else {
+            printf("%d",*(int*)arr->data[i]);
+        }
+        if (i != arr->n-1) {
+            printf(",");
+        }
+    }
+    printf("}");
+}
+
+psS32 main( psS32 argc, char* argv[] )
+{
+    psLogSetLevel( PS_LOG_INFO );
+
+    return ( ! runTestSuite( stderr, "psHash", tests, argc, argv ) );
+}
+
+psS32 hashToArray( void )
+{
+    int testNum = 0;
+    psArray* array;
+    #define BUCKETS 10
+
+    psHash* hash = psHashAlloc(BUCKETS);
+    char key[2] = "A";
+    bool found[BUCKETS];
+
+    for (int i = 0; i < BUCKETS; i++) {
+
+        array = psHashToArray(hash);
+
+        // return non-null?
+        testNum++;
+        if (array == NULL) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Failed to create an array from a psHash of %d elements.",
+                    i);
+            return testNum;
+        }
+
+        // the size correct
+        testNum++;
+        if (array->n != i) {
+            printIntArray("array",array);
+            psError(PS_ERR_UNKNOWN, false,
+                    "psHashToArray created a psArray of %d elements from a psHash of %d elements.",
+                    array->n, i);
+            return testNum;
+        }
+
+        // the values correct?
+
+        // zero out the found boolean vector
+        for (int j = 0; j < i; j++) {
+            found[j] = false;
+        }
+
+        // check if all the items in array are valid
+        for (int k = 0; k < array->n; k++) {
+            int* item = array->data[k];
+
+            testNum++;
+            if (item == NULL) {
+                printIntArray("array",array);
+                psError(PS_ERR_UNKNOWN, true,
+                        "The array position %d was NULL.",
+                        k);
+                return testNum;
+            }
+
+            testNum++;
+            if (*item < 0 || *item >= BUCKETS) {
+                printIntArray("array",array);
+                psError(PS_ERR_UNKNOWN, true,
+                        "The array position %d was invalid (%d).",
+                        k,*item);
+                return testNum;
+            }
+
+            testNum++;
+            if (found[*item]) {
+                printIntArray("array",array);
+                psError(PS_ERR_UNKNOWN, true,
+                        "The array position %d was a duplicate (%d).",
+                        k,*item);
+                return testNum;
+            }
+
+            testNum++;
+            if (psMemGetRefCounter(item) != 2) {
+                printIntArray("array",array);
+                psError(PS_ERR_UNKNOWN, true,
+                        "The array position %d was not properly reference counted (%d).",
+                        k,psMemGetRefCounter(item));
+                return testNum;
+            }
+
+            found[*item] = true;
+        }
+
+        // check that all the items in psHash was found
+        for (int j = 0; j < i; j++) {
+            testNum++;
+            if (! found[j]) {
+                printIntArray("array",array);
+                psError(PS_ERR_UNKNOWN, true,
+                        "Item %d not found in array.",
+                        j);
+                return testNum;
+            }
+        }
+
+        psFree(array);
+
+        // add one element
+        int* value = psAlloc(sizeof(int));
+        *value = i;
+        psHashAdd(hash, key, value);
+        *key += 1; // increment the key value
+
+        psFree(value);
+    }
+
+    psFree(hash);
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
+    array = psHashToArray(NULL);
+    testNum++;
+    if (array != NULL) {
+        printIntArray("array",array);
+        psError(PS_ERR_UNKNOWN, false,
+                "psHashToArray returned non-null psArray given a null psHash.");
+        return testNum;
+    }
+
+    return 0;
+}
+
