IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 20, 2004, 2:18:05 PM (22 years ago)
Author:
harman
Message:

Added Integer array

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psSort.c

    r450 r485  
    1414 *  @author Ross Harman, MHPCC
    1515 *   
    16  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2004-04-19 20:10:46 $
     16 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2004-04-21 00:18:05 $
    1818 *
    1919 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222/******************************************************************************/
    2323/*  INCLUDE FILES                                                             */
    24 /******************************************************************************/ 
     24/******************************************************************************/
    2525
    2626#include <stdio.h>
     
    7171 *  @return  int: Result of comparsion (-1, 0, or 1).
    7272 */
    73  
     73
    7474static int psCompare(
    7575    const void *x,  /**< First float to compare. */
     
    7979    float *item1 = NULL;
    8080    float *item2 = NULL;
    81    
     81
    8282    if(x == NULL || y == NULL) {
    8383        psError(__func__, " : Line %d - Null input argument: x=%d y=%d\n", __LINE__, x, y);
    8484    }
    85    
     85
    8686    item1 = (float*)x;
    8787    item2 = (float*)y;
    88    
     88
    8989    if(item1 == NULL || item2 == NULL) {
    9090        psError(__func__, " : Line %d - Improper cast to float: item1=%d item2=%d\n", __LINE__, item1, item2);
    9191    }
    92    
     92
    9393    if(*item1 < *item2) {
    9494        return -1;
    95     }
    96     else if(*item1 > *item2) {
     95    } else if(*item1 > *item2) {
    9796        return 1;
    98     }
    99     else {
     97    } else {
    10098        return 0;
    10199    }
     
    122120        return outArray;
    123121    }
    124    
     122
    125123    if(inArray == NULL) {
    126124        psError(__func__, " : Line %d - Null input array\n", __LINE__);
    127125        return outArray;
    128126    }
    129        
     127
    130128    // Initialize values
    131129    inN = inArray->n;
     
    134132    outArr = outArray->arr;
    135133    elSize = sizeof(float);
    136    
     134
    137135    if(inN != outN) {
    138136        psError(__func__, " : Line %d - Input and output array sizes are not equal: in=%d out=%d\n", __LINE__,
     
    140138        return outArray;
    141139    }
    142    
     140
    143141    // Copy input array values into output array
    144142    for(i=0; i<inN; i++) {
    145143        outArr[i] = inArr[i];
    146144    }
    147    
     145
    148146    // Sort output array
    149147    qsort((void*)outArr, inN, elSize, psCompare);
    150    
     148
    151149    return outArray;
    152150}
     
    166164    float diff = 0.0f;
    167165    psFloatArray *tmpFloatArray = NULL;
    168    
     166
    169167    if(outArray == NULL) {
    170168        psError(__func__, " : Line %d - Null output array\n", __LINE__);
    171169        return outArray;
    172170    }
    173    
     171
    174172    if(inArray == NULL) {
    175173        psError(__func__, " : Line %d - Null input array\n", __LINE__);
     
    189187    }
    190188
    191     tmpFloatArray = psFloatArrayAlloc(inN);
     189    tmpFloatArray = psFloatArrayAlloc(inN, inN);
    192190    tmpFloatArray = psSort(tmpFloatArray, inArray);
    193    
     191
    194192    for(i=0; i<inN; i++) {
    195193        tempVal = tmpFloatArray->arr[i];
     
    200198                break;
    201199            }
    202         } 
    203     }
    204    
     200        }
     201    }
     202
    205203    // Free temp memory
    206     psFreeFloatArray(tmpFloatArray);
    207    
    208     return outArray;   
     204    psFloatArrayFree(tmpFloatArray);
     205
     206    return outArray;
    209207}
Note: See TracChangeset for help on using the changeset viewer.