IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 645


Ignore:
Timestamp:
May 12, 2004, 8:07:22 AM (22 years ago)
Author:
harman
Message:

Extensive rework of psArray/psVector.

Location:
trunk/psLib/src
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/Makefile

    r600 r645  
    33##  Makefile:   collections
    44##
    5 ##  $Revision: 1.9 $  $Name: not supported by cvs2svn $
    6 ##  $Date: 2004-05-07 18:55:53 $
     5##  $Revision: 1.10 $  $Name: not supported by cvs2svn $
     6##  $Date: 2004-05-12 18:07:22 $
    77##
    88##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3030# Define the source objects
    3131 
    32 SRC_OBJS = psBitSet.o    \
    33            psArray.o    \
     32SRC_OBJS = psBitSet.o \
     33           psVector.o \
    3434           psSort.o
    3535
  • trunk/psLib/src/collections/psSort.c

    r578 r645  
    11/** @file  psSort.c
    22 *
    3  *  @brief Sorts arrays
    4  *
    5  *  The psSort functions use the qsort() stdlib function with a user-defined callback to sort an array of
    6  *  floats. The qsort function requires the starting point of the array, number of elements in the array, size
    7  *  of each element, and a pointer to a callback comparison function. Once called, qsort() will sort the array
     3 *  @brief Sorts vectors
     4 *
     5 *  The psSort functions use the qsort() stdlib function with a user-defined callback to sort an vector of
     6 *  floats. The qsort function requires the starting point of the vector, number of elements in the vector, size
     7 *  of each element, and a pointer to a callback comparison function. Once called, qsort() will sort the vector
    88 *  contents in ascending order according to the comparison function. The comparison function is called with
    99 *  two arguments that point to the objects being compared - in this case two floats. The comparison function
    1010 *  must return an integer less than, equal to, or greater than zero if the first argument is considered to be
    1111 *  respectively less than, equal to, or greater than the second. If two members compare as equal, their order
    12  *  in the sorted array is undefined.
     12 *  in the sorted vector is undefined.
    1313 *
    1414 *  @author Ross Harman, MHPCC
    1515 *   
    16  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2004-05-05 20:43:22 $
     16 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2004-05-12 18:07:22 $
    1818 *
    1919 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3030#include <float.h>
    3131
    32 #include "psArray.h"
     32#include "psVector.h"
    3333#include "psSort.h"
    3434#include "psError.h"
     
    6767 *  compared. The comparison function must return an integer less than, equal to, or greater than zero if
    6868 *  the first argument is considered to be respectively less than, equal to, or greater than the second. If
    69  *  two members compare as equal, their order in the sorted array is undefined.
     69 *  two members compare as equal, their order in the sorted vector is undefined.
    7070 *
    7171 *  @return  int: Result of comparsion (-1, 0, or 1).
     
    104104/*****************************************************************************/
    105105
    106 psArray *psSort(
    107     psArray *restrict outArray,        /**< Sorted output array. */
    108     const psArray *restrict inArray    /**< Input array to sort. */
     106psVector *psSort(
     107    psVector *restrict outVector,        /**< Sorted output vector. */
     108    const psVector *restrict inVector    /**< Input vector to sort. */
    109109)
    110110{
     
    113113    int i = 0;
    114114    int elSize = 0;
    115     float *inArr = NULL;
    116     float *outArr = NULL;
    117 
    118     if(outArray == NULL) {
    119         psError(__func__, " : Line %d - Null output array\n", __LINE__);
    120         return outArray;
    121     }
    122 
    123     if(inArray == NULL) {
    124         psError(__func__, " : Line %d - Null input array\n", __LINE__);
    125         return outArray;
     115    float *inVec = NULL;
     116    float *outVec = NULL;
     117
     118    if(outVector == NULL) {
     119        psError(__func__, " : Line %d - Null output vector\n", __LINE__);
     120        return outVector;
     121    }
     122
     123    if(inVector == NULL) {
     124        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
     125        return outVector;
    126126    }
    127127
    128128    // Initialize values
    129     inN = inArray->n;
    130     outN = outArray->n;
    131     inArr = inArray->arr.fltArr;
    132     outArr = outArray->arr.fltArr;
     129    inN = inVector->n;
     130    outN = outVector->n;
     131    inVec = inVector->vec.f;
     132    outVec = outVector->vec.f;
    133133    elSize = sizeof(float);
    134134
    135135    if(inN != outN) {
    136         psError(__func__, " : Line %d - Input and output array sizes are not equal: in=%d out=%d\n", __LINE__,
     136        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
    137137                inN, outN);
    138         return outArray;
     138        return outVector;
    139139    }
    140140
    141141    if(inN == 0) {
    142         psError(__func__, " : Line %d - No elements in use for input array\n", __LINE__);
    143         return outArray;
     142        psError(__func__, " : Line %d - No elements in use for input vector\n", __LINE__);
     143        return outVector;
    144144    }
    145145
    146146    if(outN == 0) {
    147         psError(__func__, " : Line %d - No elements in use for output array\n", __LINE__);
    148         return outArray;
    149     }
    150 
    151     // Copy input array values into output array
     147        psError(__func__, " : Line %d - No elements in use for output vector\n", __LINE__);
     148        return outVector;
     149    }
     150
     151    // Copy input vector values into output vector
    152152    for(i=0; i<inN; i++) {
    153         outArr[i] = inArr[i];
    154     }
    155 
    156     // Sort output array
    157     qsort((void*)outArr, inN, elSize, psCompare);
    158 
    159     return outArray;
     153        outVec[i] = inVec[i];
     154    }
     155
     156    // Sort output vector
     157    qsort((void*)outVec, inN, elSize, psCompare);
     158
     159    return outVector;
    160160}
    161161
    162 psArray *psSortIndex(
    163     psArray *restrict outArray,         /**< Output array of sorted indices. */
    164     const psArray *restrict inArray     /**< Input array to be sorted. */
     162psVector *psSortIndex(
     163    psVector *restrict outVector,         /**< Output vector of sorted indices. */
     164    const psVector *restrict inVector     /**< Input vector to be sorted. */
    165165)
    166166{
     
    170170    int j = 0;
    171171    float tempVal = 0.0f;
    172     float *inArr = NULL;
    173     int *outArr = NULL;
     172    float *inVec = NULL;
     173    int *outVec = NULL;
    174174    float diff = 0.0f;
    175     psArray *tmpFloatArray = NULL;
    176 
    177     if(outArray == NULL) {
    178         psError(__func__, " : Line %d - Null output array\n", __LINE__);
    179         return outArray;
    180     }
    181 
    182     if(inArray == NULL) {
    183         psError(__func__, " : Line %d - Null input array\n", __LINE__);
    184         return outArray;
     175    psVector *tmpFloatVector = NULL;
     176    psType tempType;
     177
     178    if(outVector == NULL) {
     179        psError(__func__, " : Line %d - Null output vector\n", __LINE__);
     180        return outVector;
     181    }
     182
     183    if(inVector == NULL) {
     184        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
     185        return outVector;
    185186    }
    186187
    187188    // Initialize values
    188     inN = inArray->n;
    189     outN = outArray->n;
    190     inArr = inArray->arr.fltArr;
    191     outArr = outArray->arr.intArr;
     189    inN = inVector->n;
     190    outN = outVector->n;
     191    inVec = inVector->vec.f;
     192    outVec = outVector->vec.i;
    192193
    193194    if(inN != outN) {
    194         psError(__func__, " : Line %d - Input and output array sizes are not equal: in=%d out=%d\n", __LINE__,
     195        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
    195196                inN, outN);
    196         return outArray;
    197     }
    198 
    199     tmpFloatArray = psFloatArrayAlloc(inN);
    200     tmpFloatArray->n = inN;
    201     tmpFloatArray = psSort(tmpFloatArray, inArray);
     197        return outVector;
     198    }
     199
     200    tempType.type = PS_TYPE_FLOAT;
     201    tmpFloatVector = psVectorAlloc(tempType, inN);
     202    tmpFloatVector->n = inN;
     203    tmpFloatVector = psSort(tmpFloatVector, inVector);
    202204
    203205    for(i=0; i<inN; i++) {
    204         tempVal = tmpFloatArray->arr.fltArr[i];
     206        tempVal = tmpFloatVector->vec.f[i];
    205207        for(j=0; j<inN; j++) {
    206             diff = fabsf(tempVal - inArr[j]);
     208            diff = fabsf(tempVal - inVec[j]);
    207209            if(diff < FLT_EPSILON) {
    208                 outArr[i] = j;
     210                outVec[i] = j;
    209211                break;
    210212            }
     
    213215
    214216    // Free temp memory
    215     psFloatArrayFree(tmpFloatArray);
    216 
    217     return outArray;
     217    psVectorFree(tmpFloatVector);
     218
     219    return outVector;
    218220}
  • trunk/psLib/src/collections/psSort.h

    r578 r645  
    1414 *  @author Ross Harman, MHPCC
    1515 *   
    16  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2004-05-05 20:43:57 $
     16 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2004-05-12 18:07:22 $
    1818 *
    1919 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4646 */
    4747
    48 psArray *psSort(psArray *restrict out, const psArray *restrict inArray);
     48psVector *psSort(psVector *restrict outVector, const psVector *restrict inVector);
    4949
    5050/** Creates an array of indices based on sort odred of float array.
     
    5656 */
    5757
    58 psArray *psSortIndex(psArray *restrict out, const psArray *restrict inArray);
     58psVector *psSortIndex(psVector *restrict outVector, const psVector *restrict inVector);
    5959
    6060#endif
Note: See TracChangeset for help on using the changeset viewer.