Index: trunk/psLib/src/collections/psVector.c
===================================================================
--- trunk/psLib/src/collections/psVector.c	(revision 1406)
+++ trunk/psLib/src/collections/psVector.c	(revision 1407)
@@ -1,2 +1,3 @@
+
 /** @file  psVector.c
 *
@@ -8,6 +9,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-06 22:34:05 $
+*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-07 00:06:06 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -15,7 +16,9 @@
 
 /******************************************************************************/
+
 /*  INCLUDE FILES                                                             */
-/******************************************************************************/
-#include <string.h>        // for memcpy
+
+/******************************************************************************/
+#include <string.h>                        // for memcpy
 #include <stdlib.h>
 #include <math.h>
@@ -28,5 +31,7 @@
 
 /******************************************************************************/
+
 /*  DEFINE STATEMENTS                                                         */
+
 /******************************************************************************/
 
@@ -34,5 +39,7 @@
 
 /******************************************************************************/
+
 /*  TYPE DEFINITIONS                                                          */
+
 /******************************************************************************/
 
@@ -40,5 +47,7 @@
 
 /*****************************************************************************/
+
 /*  GLOBAL VARIABLES                                                         */
+
 /*****************************************************************************/
 
@@ -46,5 +55,7 @@
 
 /*****************************************************************************/
+
 /*  FILE STATIC VARIABLES                                                    */
+
 /*****************************************************************************/
 
@@ -52,27 +63,31 @@
 
 /*****************************************************************************/
+
 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
-/*****************************************************************************/
-static void vectorFree( psVector *restrict psVec );
-
-/*****************************************************************************/
+
+/*****************************************************************************/
+static void vectorFree(psVector * restrict psVec);
+
+/*****************************************************************************/
+
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
-/*****************************************************************************/
-psVector* psVectorAlloc( unsigned int nalloc, psElemType elemType )
-{
-    psVector * psVec = NULL;
+
+/*****************************************************************************/
+psVector *psVectorAlloc(unsigned int nalloc, psElemType elemType)
+{
+    psVector *psVec = NULL;
     int elementSize = 0;
 
     // Invalid nalloc
-    if ( nalloc < 1 ) {
-        psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc );
+    if (nalloc < 1) {
+        psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc);
         return NULL;
     }
 
-    elementSize = PSELEMTYPE_SIZEOF( elemType );
+    elementSize = PSELEMTYPE_SIZEOF(elemType);
 
     // Create vector struct
-    psVec = ( psVector * ) psAlloc( sizeof( psVector ) );
-    p_psMemSetDeallocator( psVec, ( psFreeFcn ) vectorFree );
+    psVec = (psVector *) psAlloc(sizeof(psVector));
+    p_psMemSetDeallocator(psVec, (psFreeFcn) vectorFree);
 
     psVec->type.dimen = PS_DIMEN_VECTOR;
@@ -82,10 +97,10 @@
 
     // Create vector data array
-    psVec->data.V = psAlloc( nalloc * elementSize );
+    psVec->data.V = psAlloc(nalloc * elementSize);
 
     return psVec;
 }
 
-psVector *psVectorRealloc( unsigned int nalloc, psVector *restrict in )
+psVector *psVectorRealloc(unsigned int nalloc, psVector * restrict in)
 {
     int elementSize = 0;
@@ -93,52 +108,48 @@
 
     // Invalid nalloc
-    if ( nalloc < 1 ) {
-        psError( __func__, "Invalid value for realloc (%d)\n", nalloc );
+    if (nalloc < 1) {
+        psError(__func__, "Invalid value for realloc (%d)\n", nalloc);
         return NULL;
     }
 
-    if ( in == NULL ) {
-        psError( __func__, "Null input vector\n" );
+    if (in == NULL) {
+        psError(__func__, "Null input vector\n");
         return NULL;
-    } else
-        if ( in->nalloc != nalloc ) {                    // No need to realloc to same size
-            elemType = in->type.type;
-            elementSize = PSELEMTYPE_SIZEOF( elemType );
-            if ( nalloc < in->n ) {
-                in->n = nalloc;
-            }
-
-            // Realloc after decrementation to avoid accessing freed array elements
-            in->data.V = psRealloc( in->data.V, nalloc * elementSize );
-            in->nalloc = nalloc;
+    } else if (in->nalloc != nalloc) {     // No need to realloc to same size
+        elemType = in->type.type;
+        elementSize = PSELEMTYPE_SIZEOF(elemType);
+        if (nalloc < in->n) {
+            in->n = nalloc;
         }
+        // Realloc after decrementation to avoid accessing freed array elements
+        in->data.V = psRealloc(in->data.V, nalloc * elementSize);
+        in->nalloc = nalloc;
+    }
 
     return in;
 }
 
-psVector *psVectorRecycle( psVector *restrict in, unsigned int nalloc, psElemType type )
+psVector *psVectorRecycle(psVector * restrict in, unsigned int nalloc, psElemType type)
 {
     psElemType elemType;
 
-    if ( in == NULL ) {
-        return psVectorAlloc( nalloc, type );
+    if (in == NULL) {
+        return psVectorAlloc(nalloc, type);
     }
 
     elemType = in->type.type;
 
-    if ( in->nalloc == nalloc && elemType == type ) {
+    if (in->nalloc == nalloc && elemType == type) {
         // it is proper size/type already
         return in;
     }
-
     // Invalid nalloc
-    if ( nalloc < 1 ) {
-        psError( __func__, "Invalid value for nalloc (%d)\n", nalloc );
-        psFree( in );
+    if (nalloc < 1) {
+        psError(__func__, "Invalid value for nalloc (%d)\n", nalloc);
+        psFree(in);
         return NULL;
     }
 
-
-    in->data.V = psRealloc( in->data.V, nalloc * PSELEMTYPE_SIZEOF( type ) );
+    in->data.V = psRealloc(in->data.V, nalloc * PSELEMTYPE_SIZEOF(type));
 
     in->type.type = type;
@@ -149,5 +160,5 @@
 }
 
-psVector *psVectorSort( psVector *restrict outVector, const psVector *restrict inVector )
+psVector *psVectorSort(psVector * restrict outVector, const psVector * restrict inVector)
 {
     int inN = 0;
@@ -158,6 +169,6 @@
     psElemType inType = 0;
 
-    if ( inVector == NULL ) {
-        psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
+    if (inVector == NULL) {
+        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
         return outVector;
     }
@@ -166,8 +177,8 @@
     inN = inVector->n;
     inVec = inVector->data.V;
-    elSize = PSELEMTYPE_SIZEOF( inType );
-
-    if ( outVector == NULL ) {
-        outVector = psVectorAlloc( inN, inType );
+    elSize = PSELEMTYPE_SIZEOF(inType);
+
+    if (outVector == NULL) {
+        outVector = psVectorAlloc(inN, inType);
         outVector->n = inVector->n;
     }
@@ -176,63 +187,62 @@
     outVec = outVector->data.V;
 
-    if ( inN != outN ) {
-        psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
-                 inN, outN );
-        return outVector;
-    }
-
-    if ( inType != outVector->type.type ) {
-        psError( __func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
-                 inType, outVector->type.type );
-        return outVector;
-    }
-
-    if ( inN == 0 ) {
-        psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ );
-        return outVector;
-    }
-
-    if ( outN == 0 ) {
-        psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ );
-        return outVector;
-    }
-
+    if (inN != outN) {
+        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
+                __LINE__, inN, outN);
+        return outVector;
+    }
+
+    if (inType != outVector->type.type) {
+        psError(__func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
+                inType, outVector->type.type);
+        return outVector;
+    }
+
+    if (inN == 0) {
+        psError(__func__, " : Line %d - No elements in use for input vector\n", __LINE__);
+        return outVector;
+    }
+
+    if (outN == 0) {
+        psError(__func__, " : Line %d - No elements in use for output vector\n", __LINE__);
+        return outVector;
+    }
     // Copy input vector values into output vector
-    memcpy( outVec, inVec, elSize * outN );
+    memcpy(outVec, inVec, elSize * outN);
 
     // Sort output vector
-    switch ( inType ) {
+    switch (inType) {
     case PS_TYPE_U8:
-        qsort( outVec, inN, elSize, psCompareU8 );
+        qsort(outVec, inN, elSize, psCompareU8);
         break;
     case PS_TYPE_U16:
-        qsort( outVec, inN, elSize, psCompareU16 );
+        qsort(outVec, inN, elSize, psCompareU16);
         break;
     case PS_TYPE_U32:
-        qsort( outVec, inN, elSize, psCompareU32 );
+        qsort(outVec, inN, elSize, psCompareU32);
         break;
     case PS_TYPE_U64:
-        qsort( outVec, inN, elSize, psCompareU64 );
+        qsort(outVec, inN, elSize, psCompareU64);
         break;
     case PS_TYPE_S8:
-        qsort( outVec, inN, elSize, psCompareS8 );
+        qsort(outVec, inN, elSize, psCompareS8);
         break;
     case PS_TYPE_S16:
-        qsort( outVec, inN, elSize, psCompareS16 );
+        qsort(outVec, inN, elSize, psCompareS16);
         break;
     case PS_TYPE_S32:
-        qsort( outVec, inN, elSize, psCompareS32 );
+        qsort(outVec, inN, elSize, psCompareS32);
         break;
     case PS_TYPE_S64:
-        qsort( outVec, inN, elSize, psCompareS64 );
+        qsort(outVec, inN, elSize, psCompareS64);
         break;
     case PS_TYPE_F32:
-        qsort( outVec, inN, elSize, psCompareF32 );
+        qsort(outVec, inN, elSize, psCompareF32);
         break;
     case PS_TYPE_F64:
-        qsort( outVec, inN, elSize, psCompareF64 );
+        qsort(outVec, inN, elSize, psCompareF64);
         break;
     default:
-        psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
+        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
     }
 
@@ -251,5 +261,5 @@
 }
 
-psVector *psVectorSortIndex( psVector *restrict outVector, const psVector *restrict inVector )
+psVector *psVectorSortIndex(psVector * restrict outVector, const psVector * restrict inVector)
 {
     int inN = 0;
@@ -263,6 +273,6 @@
     psElemType inType = 0;
 
-    if ( inVector == NULL ) {
-        psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
+    if (inVector == NULL) {
+        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
         return outVector;
     }
@@ -272,6 +282,6 @@
     inType = inVector->type.type;
 
-    if ( outVector == NULL ) {
-        outVector = psVectorAlloc( inN, PS_TYPE_U32 );
+    if (outVector == NULL) {
+        outVector = psVectorAlloc(inN, PS_TYPE_U32);
         outVector->n = inN;
     }
@@ -280,68 +290,68 @@
     outVec = outVector->data.V;
 
-    if ( inN != outN ) {
-        psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
-                 __LINE__, inN, outN );
-        return outVector;
-    }
-
-    if ( outVector->type.type != PS_TYPE_U32 ) {
-        psError( __func__, " : Line %d - Output vector is not of type U32: out=%d\n",
-                 __LINE__, outVector->type.type );
-        return outVector;
-    }
-
-    tmpVector = psVectorAlloc( inN, inType );
+    if (inN != outN) {
+        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
+                __LINE__, inN, outN);
+        return outVector;
+    }
+
+    if (outVector->type.type != PS_TYPE_U32) {
+        psError(__func__, " : Line %d - Output vector is not of type U32: out=%d\n",
+                __LINE__, outVector->type.type);
+        return outVector;
+    }
+
+    tmpVector = psVectorAlloc(inN, inType);
     tmpVector->n = inN;
-    tmpVector = psVectorSort( tmpVector, inVector );
+    tmpVector = psVectorSort(tmpVector, inVector);
 
     // Sort output vector
-    switch ( inType ) {
+    switch (inType) {
     case PS_TYPE_U8:
-        SORT_INDICES( U8 );
+        SORT_INDICES(U8);
         break;
     case PS_TYPE_U16:
-        SORT_INDICES( U16 );
+        SORT_INDICES(U16);
         break;
     case PS_TYPE_U32:
-        SORT_INDICES( U32 );
+        SORT_INDICES(U32);
         break;
     case PS_TYPE_U64:
-        SORT_INDICES( U64 );
+        SORT_INDICES(U64);
         break;
     case PS_TYPE_S8:
-        SORT_INDICES( S8 );
+        SORT_INDICES(S8);
         break;
     case PS_TYPE_S16:
-        SORT_INDICES( S16 );
+        SORT_INDICES(S16);
         break;
     case PS_TYPE_S32:
-        SORT_INDICES( S32 );
+        SORT_INDICES(S32);
         break;
     case PS_TYPE_S64:
-        SORT_INDICES( S64 );
+        SORT_INDICES(S64);
         break;
     case PS_TYPE_F32:
-        SORT_INDICES( F32 );
+        SORT_INDICES(F32);
         break;
     case PS_TYPE_F64:
-        SORT_INDICES( F64 );
+        SORT_INDICES(F64);
         break;
     default:
-        psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
+        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
     }
 
     // Free temp memory
-    psFree( tmpVector );
+    psFree(tmpVector);
 
     return outVector;
 }
 
-static void vectorFree( psVector *restrict psVec )
-{
-    if ( psVec == NULL ) {
-        return ;
-    }
-
-    psFree( psVec->data.V );
-}
+static void vectorFree(psVector * restrict psVec)
+{
+    if (psVec == NULL) {
+        return;
+    }
+
+    psFree(psVec->data.V);
+}
