Changeset 831 for trunk/psLib/src/collections
- Timestamp:
- Jun 2, 2004, 1:29:39 PM (22 years ago)
- Location:
- trunk/psLib/src/collections
- Files:
-
- 3 edited
-
psSort.c (modified) (4 diffs)
-
psVector.c (modified) (9 diffs)
-
psVector.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psSort.c
r670 r831 14 14 * @author Ross Harman, MHPCC 15 15 * 16 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $17 * @date $Date: 2004-0 5-13 22:47:52$16 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2004-06-02 23:29:14 $ 18 18 * 19 19 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 129 129 inN = inVector->n; 130 130 outN = outVector->n; 131 inVec = inVector-> vec.f;132 outVec = outVector-> vec.f;131 inVec = inVector->data.F32; 132 outVec = outVector->data.F32; 133 133 elSize = sizeof(float); 134 134 … … 188 188 inN = inVector->n; 189 189 outN = outVector->n; 190 inVec = inVector-> vec.f;191 outVec = outVector-> vec.i32;190 inVec = inVector->data.F32; 191 outVec = outVector->data.S32; 192 192 193 193 if(inN != outN) { … … 197 197 } 198 198 199 tmpFloatVector = psVectorAlloc( PS_TYPE_FLOAT, inN);199 tmpFloatVector = psVectorAlloc(inN, PS_TYPE_F32); 200 200 tmpFloatVector->n = inN; 201 201 tmpFloatVector = psSort(tmpFloatVector, inVector); 202 202 203 203 for(i=0; i<inN; i++) { 204 tempVal = tmpFloatVector-> vec.f[i];204 tempVal = tmpFloatVector->data.F32[i]; 205 205 for(j=0; j<inN; j++) { 206 206 diff = fabsf(tempVal - inVec[j]); -
trunk/psLib/src/collections/psVector.c
r811 r831 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $22 * @date $Date: 2004-0 5-29 01:08:46$21 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2004-06-02 23:29:14 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 64 64 /* FUNCTION IMPLEMENTATION - PUBLIC */ 65 65 /*****************************************************************************/ 66 psVector* psVectorAlloc( psElemType elemType, unsigned int nalloc)66 psVector* psVectorAlloc(unsigned int nalloc, psElemType elemType) 67 67 { 68 68 psVector *psVec = NULL; … … 86 86 87 87 // Create vector data array 88 psVec-> vec.v= psAlloc(nalloc*elementSize);88 psVec->data.V = psAlloc(nalloc*elementSize); 89 89 90 90 return psVec; 91 91 } 92 92 93 psVector *psVectorRealloc( psVector *restrict in, unsigned int nalloc)93 psVector *psVectorRealloc(unsigned int nalloc, psVector *restrict in) 94 94 { 95 95 int elementSize = 0; … … 110 110 if (elemType == PS_TYPE_PTR) { 111 111 for (int i = nalloc; i < in->n; i++) { // For reduction in vector size 112 psMemDecrRefCounter(in-> vec.vp[i]);112 psMemDecrRefCounter(in->data.PTR[i]); 113 113 } 114 114 } … … 117 117 118 118 // Realloc after decrementation to avoid accessing freed array elements 119 in-> vec.v = psRealloc(in->vec.v,nalloc*elementSize);119 in->data.V = psRealloc(in->data.V,nalloc*elementSize); 120 120 in->nalloc = nalloc; 121 121 } … … 129 129 130 130 if (in == NULL) { 131 return psVectorAlloc( type,nalloc);131 return psVectorAlloc(nalloc, type); 132 132 } 133 133 … … 150 150 if (elemType == PS_TYPE_PTR) { 151 151 for (int i = 0; i < in->n; i++) { // For reduction in vector size 152 psMemDecrRefCounter(in-> vec.vp[i]);153 in-> vec.vp[i] = NULL;152 psMemDecrRefCounter(in->data.PTR[i]); 153 in->data.PTR[i] = NULL; 154 154 } 155 155 } 156 156 157 in-> vec.v = psRealloc(in->vec.v,nalloc*PSELEMTYPE_SIZEOF(elemType));157 in->data.V = psRealloc(in->data.V,nalloc*PSELEMTYPE_SIZEOF(elemType)); 158 158 159 159 in->n = 0; … … 170 170 } 171 171 172 psFree(psVec-> vec.v);172 psFree(psVec->data.V); 173 173 psFree(psVec); 174 174 } … … 188 188 for(int i = 0; i < psVec->nalloc; i++) { 189 189 if(elemFree == NULL) { 190 psMemDecrRefCounter(psVec-> vec.vp[i]);190 psMemDecrRefCounter(psVec->data.PTR[i]); 191 191 } else { 192 elemFree(psMemDecrRefCounter(psVec-> vec.vp[i]));192 elemFree(psMemDecrRefCounter(psVec->data.PTR[i])); 193 193 } 194 psVec-> vec.vp[i] = NULL;194 psVec->data.PTR[i] = NULL; 195 195 } 196 196 } -
trunk/psLib/src/collections/psVector.h
r811 r831 1 1 /** @file psVector.h 2 2 * 3 * @brief Contains support for basic vector types3 * @brief Contains basic vector definitions and operations 4 4 * 5 * This file defines types and functions for one dimensional vectors which include: 6 * char 7 * short 8 * int 9 * long 10 * unsigned char 11 * unsigned short 12 * unsigned int 13 * unsigned long 14 * float 15 * double 16 * complex float 17 * void ** 5 * This file defines the basic type for a vector struct and functions useful 6 * in manupulating vectors. 18 7 * 8 * @author Robert DeSonia, MHPCC 19 9 * @author Ross Harman, MHPCC 20 10 * 21 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $22 * @date $Date: 2004-0 5-29 01:08:46$11 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-06-02 23:29:14 $ 23 13 * 24 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 42 32 43 33 union { 44 int8_t *i8; ///< Pointers to char integer data. 45 int16_t *i16; ///< Pointers to short integer data. 46 int32_t *i32; ///< Pointers to integer data. 47 int64_t *i64; ///< Pointers to long integer data. 48 uint8_t *ui8; ///< Pointers to unsigned char integer data. 49 uint16_t*ui16; ///< Pointers to unsigned short integer data. 50 uint32_t *ui32; ///< Pointers to unsigned integer data. 51 uint64_t *ui64; ///< Pointers to unsigned long integer data. 52 float *f; ///< Pointers to floating point data. 53 double *d; ///< Pointers to double precision data. 54 complex float *cf; ///< Pointers to complex floating point data. 55 void *v; ///< Pointers to generic void data 56 void **vp; ///< Void pointer vector. 57 }vec; ///< Union for data types. 34 psU8 *U8; ///< Unsigned 8-bit integer data. 35 psU16 *U16; ///< Unsigned 16-bit integer data. 36 psU32 *U32; ///< Unsigned 32-bit integer data. 37 psU64 *U64; ///< Unsigned 64-bit integer data. 38 psS8 *S8; ///< Signed 8-bit integer data. 39 psS16 *S16; ///< Signed 16-bit integer data. 40 psS32 *S32; ///< Signed 32-bit integer data. 41 psS64 *S64; ///< Signed 64-bit integer data. 42 psF32 *F32; ///< Single-precision float data. 43 psF64 *F64; ///< Double-precision float data. 44 psC32 *C32; ///< Single-precision complex data. 45 psC64 *C64; ///< Double-precision complex data. 46 psPTR *PTR; ///< Void pointers 47 psPTR V; ///< Pointer to data 48 } data; ///< Union for data types. 58 49 } 59 50 psVector; … … 71 62 */ 72 63 psVector *psVectorAlloc( 73 psElemType dataType, ///< Type of data to be held by vector.74 unsigned int nalloc ///< Total number of elements to make available.64 unsigned int nalloc, ///< Total number of elements to make available. 65 psElemType dataType ///< Type of data to be held by vector. 75 66 ); 76 67 … … 84 75 */ 85 76 psVector *psVectorRealloc( 86 psVector *restrict psVec, ///< Vector to reallocate.87 unsigned int nalloc ///< Total number of elements to make available.77 unsigned int nalloc, ///< Total number of elements to make available. 78 psVector *restrict psVec ///< Vector to reallocate. 88 79 ); 89 80
Note:
See TracChangeset
for help on using the changeset viewer.
