Changeset 645
- Timestamp:
- May 12, 2004, 8:07:22 AM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 added
- 3 edited
-
collections/Makefile (modified) (2 diffs)
-
collections/psSort.c (modified) (7 diffs)
-
collections/psSort.h (modified) (3 diffs)
-
collections/psVector.c (added)
-
collections/psVector.h (added)
-
mathtypes/psVector.c (added)
-
mathtypes/psVector.h (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/Makefile
r600 r645 3 3 ## Makefile: collections 4 4 ## 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 $ 7 7 ## 8 8 ## Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 30 # Define the source objects 31 31 32 SRC_OBJS = psBitSet.o \33 ps Array.o\32 SRC_OBJS = psBitSet.o \ 33 psVector.o \ 34 34 psSort.o 35 35 -
trunk/psLib/src/collections/psSort.c
r578 r645 1 1 /** @file psSort.c 2 2 * 3 * @brief Sorts arrays4 * 5 * The psSort functions use the qsort() stdlib function with a user-defined callback to sort an arrayof6 * floats. The qsort function requires the starting point of the array, number of elements in the array, size7 * of each element, and a pointer to a callback comparison function. Once called, qsort() will sort the array3 * @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 8 8 * contents in ascending order according to the comparison function. The comparison function is called with 9 9 * two arguments that point to the objects being compared - in this case two floats. The comparison function 10 10 * must return an integer less than, equal to, or greater than zero if the first argument is considered to be 11 11 * respectively less than, equal to, or greater than the second. If two members compare as equal, their order 12 * in the sorted arrayis undefined.12 * in the sorted vector is undefined. 13 13 * 14 14 * @author Ross Harman, MHPCC 15 15 * 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 $ 18 18 * 19 19 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 30 #include <float.h> 31 31 32 #include "ps Array.h"32 #include "psVector.h" 33 33 #include "psSort.h" 34 34 #include "psError.h" … … 67 67 * compared. The comparison function must return an integer less than, equal to, or greater than zero if 68 68 * 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 arrayis undefined.69 * two members compare as equal, their order in the sorted vector is undefined. 70 70 * 71 71 * @return int: Result of comparsion (-1, 0, or 1). … … 104 104 /*****************************************************************************/ 105 105 106 ps Array*psSort(107 ps Array *restrict outArray, /**< Sorted output array. */108 const ps Array *restrict inArray /**< Input arrayto sort. */106 psVector *psSort( 107 psVector *restrict outVector, /**< Sorted output vector. */ 108 const psVector *restrict inVector /**< Input vector to sort. */ 109 109 ) 110 110 { … … 113 113 int i = 0; 114 114 int elSize = 0; 115 float *in Arr= NULL;116 float *out Arr= NULL;117 118 if(out Array== NULL) {119 psError(__func__, " : Line %d - Null output array\n", __LINE__);120 return out Array;121 } 122 123 if(in Array== NULL) {124 psError(__func__, " : Line %d - Null input array\n", __LINE__);125 return out Array;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; 126 126 } 127 127 128 128 // Initialize values 129 inN = in Array->n;130 outN = out Array->n;131 in Arr = inArray->arr.fltArr;132 out Arr = outArray->arr.fltArr;129 inN = inVector->n; 130 outN = outVector->n; 131 inVec = inVector->vec.f; 132 outVec = outVector->vec.f; 133 133 elSize = sizeof(float); 134 134 135 135 if(inN != outN) { 136 psError(__func__, " : Line %d - Input and output arraysizes 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__, 137 137 inN, outN); 138 return out Array;138 return outVector; 139 139 } 140 140 141 141 if(inN == 0) { 142 psError(__func__, " : Line %d - No elements in use for input array\n", __LINE__);143 return out Array;142 psError(__func__, " : Line %d - No elements in use for input vector\n", __LINE__); 143 return outVector; 144 144 } 145 145 146 146 if(outN == 0) { 147 psError(__func__, " : Line %d - No elements in use for output array\n", __LINE__);148 return out Array;149 } 150 151 // Copy input array values into output array147 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 152 152 for(i=0; i<inN; i++) { 153 out Arr[i] = inArr[i];154 } 155 156 // Sort output array157 qsort((void*)out Arr, inN, elSize, psCompare);158 159 return out Array;153 outVec[i] = inVec[i]; 154 } 155 156 // Sort output vector 157 qsort((void*)outVec, inN, elSize, psCompare); 158 159 return outVector; 160 160 } 161 161 162 ps Array*psSortIndex(163 ps Array *restrict outArray, /**< Output arrayof sorted indices. */164 const ps Array *restrict inArray /**< Input arrayto be sorted. */162 psVector *psSortIndex( 163 psVector *restrict outVector, /**< Output vector of sorted indices. */ 164 const psVector *restrict inVector /**< Input vector to be sorted. */ 165 165 ) 166 166 { … … 170 170 int j = 0; 171 171 float tempVal = 0.0f; 172 float *in Arr= NULL;173 int *out Arr= NULL;172 float *inVec = NULL; 173 int *outVec = NULL; 174 174 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; 185 186 } 186 187 187 188 // Initialize values 188 inN = in Array->n;189 outN = out Array->n;190 in Arr = inArray->arr.fltArr;191 out Arr = outArray->arr.intArr;189 inN = inVector->n; 190 outN = outVector->n; 191 inVec = inVector->vec.f; 192 outVec = outVector->vec.i; 192 193 193 194 if(inN != outN) { 194 psError(__func__, " : Line %d - Input and output arraysizes 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__, 195 196 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); 202 204 203 205 for(i=0; i<inN; i++) { 204 tempVal = tmpFloat Array->arr.fltArr[i];206 tempVal = tmpFloatVector->vec.f[i]; 205 207 for(j=0; j<inN; j++) { 206 diff = fabsf(tempVal - in Arr[j]);208 diff = fabsf(tempVal - inVec[j]); 207 209 if(diff < FLT_EPSILON) { 208 out Arr[i] = j;210 outVec[i] = j; 209 211 break; 210 212 } … … 213 215 214 216 // Free temp memory 215 ps FloatArrayFree(tmpFloatArray);216 217 return out Array;217 psVectorFree(tmpFloatVector); 218 219 return outVector; 218 220 } -
trunk/psLib/src/collections/psSort.h
r578 r645 14 14 * @author Ross Harman, MHPCC 15 15 * 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 $ 18 18 * 19 19 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 46 46 */ 47 47 48 ps Array *psSort(psArray *restrict out, const psArray *restrict inArray);48 psVector *psSort(psVector *restrict outVector, const psVector *restrict inVector); 49 49 50 50 /** Creates an array of indices based on sort odred of float array. … … 56 56 */ 57 57 58 ps Array *psSortIndex(psArray *restrict out, const psArray *restrict inArray);58 psVector *psSortIndex(psVector *restrict outVector, const psVector *restrict inVector); 59 59 60 60 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
