Changeset 485 for trunk/psLib/src/collections/psSort.c
- Timestamp:
- Apr 20, 2004, 2:18:05 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psSort.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psSort.c
r450 r485 14 14 * @author Ross Harman, MHPCC 15 15 * 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 $ 18 18 * 19 19 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 22 /******************************************************************************/ 23 23 /* INCLUDE FILES */ 24 /******************************************************************************/ 24 /******************************************************************************/ 25 25 26 26 #include <stdio.h> … … 71 71 * @return int: Result of comparsion (-1, 0, or 1). 72 72 */ 73 73 74 74 static int psCompare( 75 75 const void *x, /**< First float to compare. */ … … 79 79 float *item1 = NULL; 80 80 float *item2 = NULL; 81 81 82 82 if(x == NULL || y == NULL) { 83 83 psError(__func__, " : Line %d - Null input argument: x=%d y=%d\n", __LINE__, x, y); 84 84 } 85 85 86 86 item1 = (float*)x; 87 87 item2 = (float*)y; 88 88 89 89 if(item1 == NULL || item2 == NULL) { 90 90 psError(__func__, " : Line %d - Improper cast to float: item1=%d item2=%d\n", __LINE__, item1, item2); 91 91 } 92 92 93 93 if(*item1 < *item2) { 94 94 return -1; 95 } 96 else if(*item1 > *item2) { 95 } else if(*item1 > *item2) { 97 96 return 1; 98 } 99 else { 97 } else { 100 98 return 0; 101 99 } … … 122 120 return outArray; 123 121 } 124 122 125 123 if(inArray == NULL) { 126 124 psError(__func__, " : Line %d - Null input array\n", __LINE__); 127 125 return outArray; 128 126 } 129 127 130 128 // Initialize values 131 129 inN = inArray->n; … … 134 132 outArr = outArray->arr; 135 133 elSize = sizeof(float); 136 134 137 135 if(inN != outN) { 138 136 psError(__func__, " : Line %d - Input and output array sizes are not equal: in=%d out=%d\n", __LINE__, … … 140 138 return outArray; 141 139 } 142 140 143 141 // Copy input array values into output array 144 142 for(i=0; i<inN; i++) { 145 143 outArr[i] = inArr[i]; 146 144 } 147 145 148 146 // Sort output array 149 147 qsort((void*)outArr, inN, elSize, psCompare); 150 148 151 149 return outArray; 152 150 } … … 166 164 float diff = 0.0f; 167 165 psFloatArray *tmpFloatArray = NULL; 168 166 169 167 if(outArray == NULL) { 170 168 psError(__func__, " : Line %d - Null output array\n", __LINE__); 171 169 return outArray; 172 170 } 173 171 174 172 if(inArray == NULL) { 175 173 psError(__func__, " : Line %d - Null input array\n", __LINE__); … … 189 187 } 190 188 191 tmpFloatArray = psFloatArrayAlloc(inN );189 tmpFloatArray = psFloatArrayAlloc(inN, inN); 192 190 tmpFloatArray = psSort(tmpFloatArray, inArray); 193 191 194 192 for(i=0; i<inN; i++) { 195 193 tempVal = tmpFloatArray->arr[i]; … … 200 198 break; 201 199 } 202 } 203 } 204 200 } 201 } 202 205 203 // Free temp memory 206 psF reeFloatArray(tmpFloatArray);207 208 return outArray; 204 psFloatArrayFree(tmpFloatArray); 205 206 return outArray; 209 207 }
Note:
See TracChangeset
for help on using the changeset viewer.
