Changeset 15076
- Timestamp:
- Sep 28, 2007, 11:03:24 AM (19 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psArray.c
r14927 r15076 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.6 2$ $Name: not supported by cvs2svn $12 * @date $Date: 2007-09-2 0 23:56:57$11 * @version $Revision: 1.63 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2007-09-28 21:03:24 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 31 31 #include "psArray.h" 32 32 #include "psLogMsg.h" 33 #include "psAbort.h" 33 34 #include "psAssert.h" 34 35 … … 243 244 } 244 245 246 // Heap sort of the index array 247 psVector *psArraySortIndex (psVector *out, psArray *in, psCompareFunc func) { 248 249 if (in == NULL) { 250 return NULL; 251 } 252 253 // XXX isn't this line a waste of space? 254 out = psVectorRecycle(out, in->n, PS_TYPE_S32); // Vector for output 255 out = psVectorCreate(out, 0, in->n, 1, PS_TYPE_S32); 256 long N = out->n; // Number of elements 257 if (N < 2) { 258 return out; 259 } 260 261 long I = N >> 1; 262 long J = N - 1; 263 264 int result; 265 266 psS32 temp; 267 psS32 *index = out->data.S32; 268 while (1) { 269 if (I > 0) { 270 // I--; 271 temp = index[--I]; 272 } else { 273 temp = index[J]; 274 index[J] = index[0]; 275 // J--; 276 if (--J == 0) { 277 index[0] = temp; 278 return out; 279 } 280 } 281 long i = I; 282 long j = (I << 1) + 1; 283 while (j <= J) { 284 result = func (in->data[index[j]], in->data[index[j+1]]); 285 if ((j < J) && (result < 0)) { 286 j++; 287 } 288 result = func (in->data[temp], in->data[index[j]]); 289 if (result < 0) { 290 index[i]=index[j]; 291 j += (i=j) + 1; 292 } else { 293 j = J + 1; 294 } 295 } 296 index[i] = temp; 297 } 298 psAbort ("impossible to reach here"); 299 } 300 245 301 psArray* psArraySort(psArray* array, 246 302 psComparePtrFunc func) -
trunk/psLib/src/types/psArray.h
r14927 r15076 10 10 * @author Joshua Hoblitt, University of Hawaii 11 11 * 12 * @version $Revision: 1.5 0$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-09-2 0 23:56:57$12 * @version $Revision: 1.51 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-09-28 21:03:24 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 21 21 #include "psType.h" 22 22 #include "psCompare.h" 23 #include "psVector.h" 23 24 24 25 /// @addtogroup DataContainer Data Containers … … 220 221 ); 221 222 223 // return the index which sorts the array 224 psVector *psArraySortIndex (psVector *outIndex, psArray *in, psCompareFunc func); 222 225 223 226 /** Set an element in the array. If the current element is non-NULL, the old
Note:
See TracChangeset
for help on using the changeset viewer.
