Changeset 1407 for trunk/psLib/src/collections
- Timestamp:
- Aug 6, 2004, 2:06:06 PM (22 years ago)
- Location:
- trunk/psLib/src/collections
- Files:
-
- 14 edited
-
psArray.c (modified) (8 diffs)
-
psArray.h (modified) (8 diffs)
-
psBitSet.c (modified) (17 diffs)
-
psBitSet.h (modified) (12 diffs)
-
psCompare.c (modified) (2 diffs)
-
psCompare.h (modified) (44 diffs)
-
psList.c (modified) (29 diffs)
-
psList.h (modified) (15 diffs)
-
psMetadata.c (modified) (27 diffs)
-
psMetadata.h (modified) (19 diffs)
-
psScalar.c (modified) (13 diffs)
-
psScalar.h (modified) (6 diffs)
-
psVector.c (modified) (18 diffs)
-
psVector.h (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psArray.c
r1406 r1407 1 1 2 /** @file psArray.c 2 3 * … … 8 9 * @author Ross Harman, MHPCC 9 10 * 10 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-08-0 6 22:34:05$11 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-08-07 00:06:06 $ 12 13 * 13 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 16 16 17 /******************************************************************************/ 18 17 19 /* INCLUDE FILES */ 20 18 21 /******************************************************************************/ 19 #include<stdlib.h> // for qsort, etc.22 #include<stdlib.h> // for qsort, etc. 20 23 21 24 #include "psMemory.h" … … 24 27 #include "psLogMsg.h" 25 28 29 /*****************************************************************************/ 30 31 /* FUNCTION IMPLEMENTATION - LOCAL */ 26 32 27 33 /*****************************************************************************/ 28 /* FUNCTION IMPLEMENTATION - LOCAL */ 29 /*****************************************************************************/ 30 static void arrayFree(psArray *restrict psArr); 34 static void arrayFree(psArray * restrict psArr); 31 35 32 36 /*****************************************************************************/ 37 33 38 /* FUNCTION IMPLEMENTATION - PUBLIC */ 39 34 40 /*****************************************************************************/ 35 psArray *psArrayAlloc(unsigned int nalloc)41 psArray *psArrayAlloc(unsigned int nalloc) 36 42 { 37 43 psArray *psArr = NULL; 38 44 39 45 // Invalid nalloc 40 if (nalloc < 1) {46 if (nalloc < 1) { 41 47 psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc); 42 48 return NULL; 43 49 } 44 45 50 // Create vector struct 46 psArr = (psArray *) psAlloc(sizeof(psArray));47 p_psMemSetDeallocator(psArr, (psFreeFcn)arrayFree);51 psArr = (psArray *) psAlloc(sizeof(psArray)); 52 p_psMemSetDeallocator(psArr, (psFreeFcn) arrayFree); 48 53 49 54 psArr->nalloc = nalloc; … … 51 56 52 57 // Create vector data array 53 psArr->data = psAlloc(nalloc *sizeof(psPTR));58 psArr->data = psAlloc(nalloc * sizeof(psPTR)); 54 59 55 60 return psArr; 56 61 } 57 62 58 psArray *psArrayRealloc(unsigned int nalloc, psArray * restrict in)63 psArray *psArrayRealloc(unsigned int nalloc, psArray * restrict in) 59 64 { 60 65 // Invalid nalloc 61 if (nalloc < 1) {66 if (nalloc < 1) { 62 67 psError(__func__, "Invalid value for realloc (%d)\n", nalloc); 63 68 return NULL; 64 69 } 65 70 66 if (in == NULL) {71 if (in == NULL) { 67 72 psError(__func__, "Null input vector\n"); 68 73 return NULL; 69 } else 70 if(in->nalloc != nalloc) { // No need to realloc to same size 71 if(nalloc < in->n) { 72 for (int i = nalloc; i < in->n; i++) { // For reduction in vector size 73 psFree(in->data[i]); 74 } 75 in->n = nalloc; 74 } else if (in->nalloc != nalloc) { // No need to realloc to same size 75 if (nalloc < in->n) { 76 for (int i = nalloc; i < in->n; i++) { // For reduction in vector size 77 psFree(in->data[i]); 76 78 } 77 78 // Realloc after decrementation to avoid accessing freed array elements 79 in->data = psRealloc(in->data,nalloc*sizeof(psPTR)); 80 in->nalloc = nalloc; 79 in->n = nalloc; 81 80 } 81 // Realloc after decrementation to avoid accessing freed array elements 82 in->data = psRealloc(in->data, nalloc * sizeof(psPTR)); 83 in->nalloc = nalloc; 84 } 82 85 83 86 return in; 84 87 } 85 88 86 static void arrayFree(psArray * restrict psArr)89 static void arrayFree(psArray * restrict psArr) 87 90 { 88 91 if (psArr == NULL) { … … 95 98 } 96 99 97 void psArrayElementFree(psArray * restrict psArr)100 void psArrayElementFree(psArray * restrict psArr) 98 101 { 99 102 100 if (psArr == NULL) {103 if (psArr == NULL) { 101 104 return; 102 105 } 103 106 104 for (int i = 0; i < psArr->n; i++) {107 for (int i = 0; i < psArr->n; i++) { 105 108 psFree(psArr->data[i]); 106 109 psArr->data[i] = NULL; … … 108 111 } 109 112 110 psArray * psArraySort(psArray* in, psComparePtrFcn compare)113 psArray *psArraySort(psArray * in, psComparePtrFcn compare) 111 114 { 112 115 if (in == NULL) { … … 114 117 } 115 118 116 qsort(in->data, in->n, sizeof(psPTR), 117 (int(*)(const void *, const void *))compare); 118 119 qsort(in->data, in->n, sizeof(psPTR), (int (*)(const void *, const void *))compare); 119 120 120 121 return in; -
trunk/psLib/src/collections/psArray.h
r1228 r1407 1 1 2 /** @file psArray.h 2 3 * … … 11 12 * @author Ross Harman, MHPCC 12 13 * 13 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-0 7-15 22:18:02$14 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-08-07 00:06:06 $ 15 16 * 16 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 19 19 20 #ifndef PS_ARRAY_H 20 # define PS_ARRAY_H21 # define PS_ARRAY_H 21 22 22 # include "psType.h"23 # include "psCompare.h"23 # include "psType.h" 24 # include "psCompare.h" 24 25 25 26 /// @addtogroup Array … … 33 34 typedef struct 34 35 { 35 unsigned int nalloc; ///< Total number of elements available.36 unsigned int n; ///< Number of elements in use.37 psPTR * data; ///< An Array of pointer elements36 unsigned int nalloc; // /< Total number of elements available. 37 unsigned int n; // /< Number of elements in use. 38 psPTR *data; // /< An Array of pointer elements 38 39 } 39 40 psArray; 40 41 41 42 /*****************************************************************************/ 43 42 44 /* FUNCTION PROTOTYPES */ 45 43 46 /*****************************************************************************/ 44 47 … … 51 54 * 52 55 */ 53 psArray *psArrayAlloc( 54 unsigned int nalloc ///< Total number of elements to make available. 55 ); 56 psArray *psArrayAlloc(unsigned int nalloc // /< Total number of elements to make available. 57 ); 56 58 57 59 /** Reallocate an array. … … 63 65 * 64 66 */ 65 psArray *psArrayRealloc( 66 unsigned int nalloc, ///< Total number of elements to make available. 67 psArray *restrict psArr ///< array to reallocate. 68 ); 67 psArray *psArrayRealloc(unsigned int nalloc, // /< Total number of elements to make available. 68 psArray * restrict psArr // /< array to reallocate. 69 ); 69 70 70 71 /** Deallocate/Dereference elements of an array. … … 75 76 * 76 77 */ 77 void psArrayElementFree( 78 psArray *restrict psArr ///< Void pointer array to destroy. 79 ); 78 void psArrayElementFree(psArray * restrict psArr // /< Void pointer array to destroy. 79 ); 80 80 81 81 /** Sort the array according to an external compare function. … … 86 86 * @return psArray* The sorted array. 87 87 */ 88 psArray * psArraySort(psArray* in, psComparePtrFcn compare);88 psArray *psArraySort(psArray * in, psComparePtrFcn compare); 89 89 90 90 /// @} -
trunk/psLib/src/collections/psBitSet.c
r1406 r1407 1 1 2 /** @file psBitSet.c 2 3 * … … 10 11 * @author Ross Harman, MHPCC 11 12 * 12 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08-0 6 22:34:05$13 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-08-07 00:06:06 $ 14 15 * 15 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 17 18 18 19 /******************************************************************************/ 20 19 21 /* INCLUDE FILES */ 22 20 23 /******************************************************************************/ 21 24 #include <string.h> … … 31 34 32 35 /******************************************************************************/ 36 33 37 /* DEFINE STATEMENTS */ 34 /******************************************************************************/ 35 36 // None 37 38 /******************************************************************************/ 38 39 /******************************************************************************/ 40 41 // None 42 43 /******************************************************************************/ 44 39 45 /* TYPE DEFINITIONS */ 40 /******************************************************************************/ 41 42 // None 43 44 /*****************************************************************************/ 46 47 /******************************************************************************/ 48 49 // None 50 51 /*****************************************************************************/ 52 45 53 /* GLOBAL VARIABLES */ 46 /*****************************************************************************/ 47 48 // None 49 50 /*****************************************************************************/ 54 55 /*****************************************************************************/ 56 57 // None 58 59 /*****************************************************************************/ 60 51 61 /* FILE STATIC VARIABLES */ 52 /*****************************************************************************/ 53 54 // None 55 56 /*****************************************************************************/ 62 63 /*****************************************************************************/ 64 65 // None 66 67 /*****************************************************************************/ 68 57 69 /* FUNCTION IMPLEMENTATION - LOCAL */ 58 /*****************************************************************************/ 59 static void psBitSetFree(psBitSet *restrict inBitSet); 60 70 71 /*****************************************************************************/ 72 static void psBitSetFree(psBitSet * restrict inBitSet); 61 73 62 74 /** Private function to create a mask. … … 70 82 { 71 83 char mask = (char)0x01; 84 72 85 // Ignore splint warning about negative bit shifts 73 /* @i@*/74 mask = mask << (bit %8);86 /* @i@ */ 87 mask = mask << (bit % 8); 75 88 76 89 return mask; … … 78 91 79 92 /*****************************************************************************/ 93 80 94 /* FUNCTION IMPLEMENTATION - PUBLIC */ 81 /*****************************************************************************/ 82 psBitSet* psBitSetAlloc(int n) 95 96 /*****************************************************************************/ 97 psBitSet *psBitSetAlloc(int n) 83 98 { 84 99 int numBytes = 0; 85 100 psBitSet *newObj = NULL; 86 101 87 if (n <= 0) {102 if (n <= 0) { 88 103 psError(__func__, " : Line %d - Allocation size must be > 0: size = %d", __LINE__, n); 89 104 return 0; 90 105 } 91 106 92 numBytes = ceil(n /8.0);107 numBytes = ceil(n / 8.0); 93 108 newObj = psAlloc(sizeof(psBitSet)); 94 if (newObj == NULL) {95 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);96 } 97 p_psMemSetDeallocator(newObj, (psFreeFcn)psBitSetFree);109 if (newObj == NULL) { 110 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); 111 } 112 p_psMemSetDeallocator(newObj, (psFreeFcn) psBitSetFree); 98 113 newObj->n = numBytes; 99 114 100 115 // Ignore splint warning about releasing pointer members, since they've not been allocated yet 101 /* @i@*/102 newObj->bits = psAlloc(sizeof(char) *numBytes);103 if (newObj->bits == NULL) {104 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);116 /* @i@ */ 117 newObj->bits = psAlloc(sizeof(char) * numBytes); 118 if (newObj->bits == NULL) { 119 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); 105 120 } 106 121 … … 110 125 } 111 126 112 static void psBitSetFree(psBitSet * restrict inBitSet)113 { 114 if (inBitSet == NULL) {127 static void psBitSetFree(psBitSet * restrict inBitSet) 128 { 129 if (inBitSet == NULL) { 115 130 psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__); 116 131 return; … … 119 134 } 120 135 121 psBitSet * psBitSetSet(psBitSet *inBitSet, int bit)122 { 123 char *byte = NULL;124 125 if (inBitSet == NULL) {136 psBitSet *psBitSetSet(psBitSet * inBitSet, int bit) 137 { 138 char *byte = NULL; 139 140 if (inBitSet == NULL) { 126 141 psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__); 127 142 return inBitSet; 128 } else 129 if(bit < 0) { 130 psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit); 131 return inBitSet; 132 } else 133 if(bit > inBitSet->n*8-1) { 134 psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit); 135 return inBitSet; 136 } 137 143 } else if (bit < 0) { 144 psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit); 145 return inBitSet; 146 } else if (bit > inBitSet->n * 8 - 1) { 147 psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit); 148 return inBitSet; 149 } 138 150 // Variable byte is the byte in the array that contains the bit to be set 139 byte = inBitSet->bits +bit/8;151 byte = inBitSet->bits + bit / 8; 140 152 *byte |= mask(bit); 141 153 … … 143 155 } 144 156 145 bool psBitSetTest(const psBitSet *inBitSet, int bit) 146 { 147 char* byte = NULL; 148 149 if(inBitSet == NULL) { 150 psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__); 151 return 0; 152 } else 153 if(bit < 0) { 154 psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit); 155 return 0; 156 } else 157 if(bit > inBitSet->n*8-1) { 158 psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit); 159 return 0; 160 } 161 157 bool psBitSetTest(const psBitSet * inBitSet, int bit) 158 { 159 char *byte = NULL; 160 161 if (inBitSet == NULL) { 162 psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__); 163 return 0; 164 } else if (bit < 0) { 165 psError(__func__, " : Line %d - Bit position too small: %d", __LINE__, bit); 166 return 0; 167 } else if (bit > inBitSet->n * 8 - 1) { 168 psError(__func__, " : Line %d - Bit position too large: %d", __LINE__, bit); 169 return 0; 170 } 162 171 // Variable byte is the byte in the array that contains the bit to be tested 163 byte = inBitSet->bits +bit/8;164 if ((int)(*byte&mask(bit)) == 0) {172 byte = inBitSet->bits + bit / 8; 173 if ((int)(*byte & mask(bit)) == 0) { 165 174 return 0; 166 175 } … … 169 178 } 170 179 171 psBitSet * psBitSetOp(psBitSet *outBitSet, const psBitSet *restrict inBitSet1, char *operator,172 const psBitSet * restrict inBitSet2)180 psBitSet *psBitSetOp(psBitSet * outBitSet, const psBitSet * restrict inBitSet1, char *operator, 181 const psBitSet * restrict inBitSet2) 173 182 { 174 183 int i = 0; … … 179 188 char *inBits2 = NULL; 180 189 181 if (inBitSet1 == NULL) {190 if (inBitSet1 == NULL) { 182 191 psError(__func__, " : Line %d - Null psBitSet for inBitSet1 argument", __LINE__); 183 192 return outBitSet; 184 193 } 185 194 186 if (operator == NULL) {195 if (operator == NULL) { 187 196 psError(__func__, " : Line %d - Null input operator\n", __LINE__); 188 197 return outBitSet; 189 198 } 190 199 191 if (inBitSet2 == NULL) {200 if (inBitSet2 == NULL) { 192 201 psError(__func__, " : Line %d - Null psBitSet for inBitSet2 argument", __LINE__); 193 202 return outBitSet; 194 203 } 195 204 196 if (outBitSet == NULL) {197 outBitSet = psBitSetAlloc(inBitSet1->n *8);198 } 199 200 if (inBitSet1->n != inBitSet2->n || outBitSet->n != inBitSet1->n) {205 if (outBitSet == NULL) { 206 outBitSet = psBitSetAlloc(inBitSet1->n * 8); 207 } 208 209 if (inBitSet1->n != inBitSet2->n || outBitSet->n != inBitSet1->n) { 201 210 psError(__func__, " : Line %d - psBitSet sizes not the same", __LINE__); 202 211 return outBitSet; … … 209 218 210 219 tempChar = toupper(operator[0]); 211 switch (tempChar) {220 switch (tempChar) { 212 221 case 'A': 213 for (i=0; i<n; i++) {222 for (i = 0; i < n; i++) { 214 223 outBits[i] = inBits1[i] & inBits2[i]; 215 224 } 216 225 break; 217 226 case 'O': 218 for (i=0; i<n; i++) {227 for (i = 0; i < n; i++) { 219 228 outBits[i] = inBits1[i] | inBits2[i]; 220 229 } 221 230 break; 222 231 case 'X': 223 for (i=0; i<n; i++) {232 for (i = 0; i < n; i++) { 224 233 outBits[i] = inBits1[i] ^ inBits2[i]; 225 234 } … … 232 241 } 233 242 234 psBitSet * psBitSetNot(psBitSet *outBitSet, const psBitSet *restrict inBitSet)243 psBitSet *psBitSetNot(psBitSet * outBitSet, const psBitSet * restrict inBitSet) 235 244 { 236 245 int i = 0; … … 239 248 char *inBits = NULL; 240 249 241 if (inBitSet == NULL) {250 if (inBitSet == NULL) { 242 251 psError(__func__, " : Line %d - Null psBitSet for inBitSet argument", __LINE__); 243 252 return outBitSet; … … 245 254 246 255 n = inBitSet->n; 247 if (n == 0) {256 if (n == 0) { 248 257 psError(__func__, " : Line %d - No elements in inBitSet", __LINE__); 249 258 return outBitSet; 250 259 } 251 260 252 if (outBitSet == NULL) {253 outBitSet = psBitSetAlloc(n *8);254 } 255 256 if (inBitSet->n != outBitSet->n) {261 if (outBitSet == NULL) { 262 outBitSet = psBitSetAlloc(n * 8); 263 } 264 265 if (inBitSet->n != outBitSet->n) { 257 266 psError(__func__, " : Line %d - psBitSet sizes not the same", __LINE__); 258 267 return outBitSet; … … 262 271 inBits = inBitSet->bits; 263 272 264 for (i=0; i<n; i++) {273 for (i = 0; i < n; i++) { 265 274 outBits[i] = ~inBits[i]; 266 275 } … … 269 278 } 270 279 271 char *psBitSetToString(const psBitSet * restrict inBitSet)280 char *psBitSetToString(const psBitSet * restrict inBitSet) 272 281 { 273 282 int i = 0; 274 int numBits = inBitSet->n*8; 275 char* outString = psAlloc((size_t)numBits+1); 276 if(outString == NULL) { 277 psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__); 278 } 279 280 for(i=0; i<numBits; i++) { 281 outString[numBits-i-1] = (psBitSetTest(inBitSet, i) == 1)?'1':'0'; 283 int numBits = inBitSet->n * 8; 284 char *outString = psAlloc((size_t) numBits + 1); 285 286 if (outString == NULL) { 287 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); 288 } 289 290 for (i = 0; i < numBits; i++) { 291 outString[numBits - i - 1] = (psBitSetTest(inBitSet, i) == 1) ? '1' : '0'; 282 292 } 283 293 -
trunk/psLib/src/collections/psBitSet.h
r1172 r1407 1 1 2 /** @file psBitSet.h 2 3 * … … 12 13 * @author Ross Harman, MHPCC 13 14 * 14 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-0 7-01 21:48:11$15 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2004-08-07 00:06:06 $ 16 17 * 17 18 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 20 20 21 #ifndef PSBITSET_H 21 # define PSBITSET_H22 # define PSBITSET_H 22 23 23 24 /// @addtogroup BitSet … … 25 26 26 27 /******************************************************************************/ 28 27 29 /* TYPE DEFINITIONS */ 30 28 31 /******************************************************************************/ 29 32 … … 35 38 typedef struct 36 39 { 40 37 41 int n; /**< Number of bytes in the array */ 42 38 43 char *bits; /**< Aray of bytes holding bits */ 39 44 } … … 41 46 42 47 /*****************************************************************************/ 48 43 49 /* FUNCTION PROTOTYPES */ 50 44 51 /*****************************************************************************/ 45 52 … … 51 58 * @return psBitSet*: Pointer to struct containing array of bits and size of array. 52 59 */ 60 53 61 /*@null@*/ 54 psBitSet* psBitSetAlloc( 55 int n /**< Number of bits in psBitSet array */ 56 ); 62 63 psBitSet *psBitSetAlloc(int n 64 /**< Number of bits in psBitSet array */ 65 ); 57 66 58 67 /** Set a bit. … … 64 73 * @return psBitSet*: Pointer to struct containing psBitSet. 65 74 */ 66 psBitSet* psBitSetSet( 67 /*@returned@*/psBitSet *restrict inMask, /**< Pointer to psBitSet to be set. */ 68 int bit /**< Bit to be set. */ 75 psBitSet *psBitSetSet( 76 77 /* @returned@ */ psBitSet * restrict inMask, 78 /**< Pointer to psBitSet to be set. */ 79 80 int bit/**< Bit to be set. */ 69 81 ); 70 82 … … 78 90 * @return int: Value of bit, either one or zero. 79 91 */ 80 bool psBitSetTest( 81 const psBitSet *restrict inMask, /**< Pointer psBitSet to be tested. */ 82 int bit /**< Bit to be tested. */ 83 ); 92 93 bool psBitSetTest(const psBitSet * restrict inMask, 94 /**< Pointer psBitSet to be tested. */ 95 96 int bit /**< Bit to be tested. */ 97 ); 84 98 85 99 /** Perform a binary operation on two psBitSets … … 90 104 * @return psBitSet*: Pointer to struct containing result of binary operation. 91 105 */ 92 psBitSet* psBitSetOp( 93 /*@returned@*/psBitSet *restrict outMask, /**< Resulting psBitSet from binary operation */ 94 const psBitSet *restrict inMask1, /**< First psBitSet on which to operate */ 95 char *operator, /**< Bit operation */ 96 const psBitSet *restrict inMask2 /**< First psBitSet on which to operate */ 106 psBitSet *psBitSetOp( 107 108 /* @returned@ */ psBitSet * restrict outMask, 109 /**< Resulting psBitSet from binary operation */ 110 111 const psBitSet * restrict inMask1, 112 /**< First psBitSet on which to operate */ 113 114 char *operator, /**< Bit operation */ 115 116 const psBitSet * restrict inMask2 117 /**< First psBitSet on which to operate */ 97 118 ); 98 119 … … 103 124 * @return psBitSet*: Pointer to struct containing result of operation. 104 125 */ 105 psBitSet* psBitSetNot( 106 psBitSet *outBitSet, /**< Resulting psBitSet from operation */ 107 const psBitSet *restrict inBitSet /**< Input psBitSet */ 108 ); 126 127 psBitSet *psBitSetNot(psBitSet * outBitSet, 128 /**< Resulting psBitSet from operation */ 129 130 const psBitSet * restrict inBitSet 131 /**< Input psBitSet */ 132 ); 109 133 110 134 /** Convert the psBitSet to a string of ones and zeros. … … 115 139 * @return char*: Pointer to character array containing string data. 116 140 */ 117 char *psBitSetToString( 118 const psBitSet *restrict inMask /**< psBitSet to convert */ 119 ); 141 142 char *psBitSetToString(const psBitSet * restrict inMask 143 /**< psBitSet to convert */ 144 ); 120 145 121 146 /// @} -
trunk/psLib/src/collections/psCompare.c
r1393 r1407 1 1 2 /** @file psCompare.c 2 3 * @brief Comparison functions for sorting routines … … 6 7 * @author Robert Daniel DeSonia, MHPCC 7 8 * 8 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-08-0 5 19:38:52$9 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-08-07 00:06:06 $ 10 11 * 11 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/collections/psCompare.h
r1111 r1407 1 1 #if !defined(PS_COMPARE_H) 2 # define PS_COMPARE_H2 # define PS_COMPARE_H 3 3 4 4 /** @file psCompare.h … … 9 9 * @ingroup Compare 10 10 * 11 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-0 6-28 20:36:37$11 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-08-07 00:06:06 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 26 * than, equal to, or greater than the second. 27 27 */ 28 typedef int (*psComparePtrFcn) (const void** a, const void**b);28 typedef int (*psComparePtrFcn) (const void **a, const void **b); 29 29 30 30 /** A comparison function for sorting. … … 34 34 * than, equal to, or greater than the second. 35 35 */ 36 typedef int (*psCompareFcn) (const void* a, const void*b);36 typedef int (*psCompareFcn) (const void *a, const void *b); 37 37 38 38 /** Compare function of psS8 data. For use with psListSort. … … 42 42 * than, equal to, or greater than the second. 43 43 */ 44 int psCompareS8Ptr(const void ** a, const void**b);44 int psCompareS8Ptr(const void **a, const void **b); 45 45 46 46 /** Compare function of psS16 data. For use with psListSort. … … 50 50 * than, equal to, or greater than the second. 51 51 */ 52 int psCompareS16Ptr(const void ** a, const void**b);52 int psCompareS16Ptr(const void **a, const void **b); 53 53 54 54 /** Compare function of psS32 data. For use with psListSort. … … 58 58 * than, equal to, or greater than the second. 59 59 */ 60 int psCompareS32Ptr(const void ** a, const void**b);60 int psCompareS32Ptr(const void **a, const void **b); 61 61 62 62 /** Compare function of psS64 data. For use with psListSort. … … 66 66 * than, equal to, or greater than the second. 67 67 */ 68 int psCompareS64Ptr(const void ** a, const void**b);68 int psCompareS64Ptr(const void **a, const void **b); 69 69 70 70 /** Compare function of psU8 data. For use with psListSort. … … 74 74 * than, equal to, or greater than the second. 75 75 */ 76 int psCompareU8Ptr(const void ** a, const void**b);76 int psCompareU8Ptr(const void **a, const void **b); 77 77 78 78 /** Compare function of psU16 data. For use with psListSort. … … 82 82 * than, equal to, or greater than the second. 83 83 */ 84 int psCompareU16Ptr(const void ** a, const void**b);84 int psCompareU16Ptr(const void **a, const void **b); 85 85 86 86 /** Compare function of psU32 data. For use with psListSort. … … 90 90 * than, equal to, or greater than the second. 91 91 */ 92 int psCompareU32Ptr(const void ** a, const void**b);92 int psCompareU32Ptr(const void **a, const void **b); 93 93 94 94 /** Compare function of psU64 data. For use with psListSort. … … 98 98 * than, equal to, or greater than the second. 99 99 */ 100 int psCompareU64Ptr(const void ** a, const void**b);100 int psCompareU64Ptr(const void **a, const void **b); 101 101 102 102 /** Compare function of psF32 data. For use with psListSort. … … 106 106 * than, equal to, or greater than the second. 107 107 */ 108 int psCompareF32Ptr(const void ** a, const void**b);108 int psCompareF32Ptr(const void **a, const void **b); 109 109 110 110 /** Compare function of psF64 data. For use with psListSort. … … 114 114 * than, equal to, or greater than the second. 115 115 */ 116 int psCompareF64Ptr(const void ** a, const void**b);116 int psCompareF64Ptr(const void **a, const void **b); 117 117 118 118 /** Compare function of psS8 data. For use with psListSort for descending ordering. … … 122 122 * than, equal to, or less than the second. 123 123 */ 124 int psCompareDescendingS8Ptr(const void ** a, const void**b);124 int psCompareDescendingS8Ptr(const void **a, const void **b); 125 125 126 126 /** Compare function of psS16 data. For use with psListSort for descending ordering. … … 130 130 * than, equal to, or less than the second. 131 131 */ 132 int psCompareDescendingS16Ptr(const void ** a, const void**b);132 int psCompareDescendingS16Ptr(const void **a, const void **b); 133 133 134 134 /** Compare function of psS32 data. For use with psListSort for descending ordering. … … 138 138 * than, equal to, or less than the second. 139 139 */ 140 int psCompareDescendingS32Ptr(const void ** a, const void**b);140 int psCompareDescendingS32Ptr(const void **a, const void **b); 141 141 142 142 /** Compare function of psS64 data. For use with psListSort for descending ordering. … … 146 146 * than, equal to, or less than the second. 147 147 */ 148 int psCompareDescendingS64Ptr(const void ** a, const void**b);148 int psCompareDescendingS64Ptr(const void **a, const void **b); 149 149 150 150 /** Compare function of psU8 data. For use with psListSort for descending ordering. … … 154 154 * than, equal to, or less than the second. 155 155 */ 156 int psCompareDescendingU8Ptr(const void ** a, const void**b);156 int psCompareDescendingU8Ptr(const void **a, const void **b); 157 157 158 158 /** Compare function of psU16 data. For use with psListSort for descending ordering. … … 162 162 * than, equal to, or less than the second. 163 163 */ 164 int psCompareDescendingU16Ptr(const void ** a, const void**b);164 int psCompareDescendingU16Ptr(const void **a, const void **b); 165 165 166 166 /** Compare function of psU32 data. For use with psListSort for descending ordering. … … 170 170 * than, equal to, or lessg than the second. 171 171 */ 172 int psCompareDescendingU32Ptr(const void ** a, const void**b);172 int psCompareDescendingU32Ptr(const void **a, const void **b); 173 173 174 174 /** Compare function of psU64 data. For use with psListSort for descending ordering. … … 178 178 * than, equal to, or lessg than the second. 179 179 */ 180 int psCompareDescendingU64Ptr(const void ** a, const void**b);180 int psCompareDescendingU64Ptr(const void **a, const void **b); 181 181 182 182 /** Compare function of psF32 data. For use with psListSort for descending ordering. … … 186 186 * than, equal to, or lessg than the second. 187 187 */ 188 int psCompareDescendingF32Ptr(const void ** a, const void**b);188 int psCompareDescendingF32Ptr(const void **a, const void **b); 189 189 190 190 /** Compare function of psF64 data. For use with psListSort for descending ordering. … … 194 194 * than, equal to, or lessg than the second. 195 195 */ 196 int psCompareDescendingF64Ptr(const void ** a, const void**b);196 int psCompareDescendingF64Ptr(const void **a, const void **b); 197 197 198 198 /** Compare function of psS8 data. … … 202 202 * than, equal to, or greater than the second. 203 203 */ 204 int psCompareS8(const void * a, const void*b);204 int psCompareS8(const void *a, const void *b); 205 205 206 206 /** Compare function of psS16 data. … … 210 210 * than, equal to, or greater than the second. 211 211 */ 212 int psCompareS16(const void * a, const void*b);212 int psCompareS16(const void *a, const void *b); 213 213 214 214 /** Compare function of psS32 data. … … 218 218 * than, equal to, or greater than the second. 219 219 */ 220 int psCompareS32(const void * a, const void*b);220 int psCompareS32(const void *a, const void *b); 221 221 222 222 /** Compare function of psS64 data. … … 226 226 * than, equal to, or greater than the second. 227 227 */ 228 int psCompareS64(const void * a, const void*b);228 int psCompareS64(const void *a, const void *b); 229 229 230 230 /** Compare function of psU8 data. … … 234 234 * than, equal to, or greater than the second. 235 235 */ 236 int psCompareU8(const void * a, const void*b);236 int psCompareU8(const void *a, const void *b); 237 237 238 238 /** Compare function of psU16 data. … … 242 242 * than, equal to, or greater than the second. 243 243 */ 244 int psCompareU16(const void * a, const void*b);244 int psCompareU16(const void *a, const void *b); 245 245 246 246 /** Compare function of psU32 data. … … 250 250 * than, equal to, or greater than the second. 251 251 */ 252 int psCompareU32(const void * a, const void*b);252 int psCompareU32(const void *a, const void *b); 253 253 254 254 /** Compare function of psU64 data. … … 258 258 * than, equal to, or greater than the second. 259 259 */ 260 int psCompareU64(const void * a, const void*b);260 int psCompareU64(const void *a, const void *b); 261 261 262 262 /** Compare function of psF32 data. … … 266 266 * than, equal to, or greater than the second. 267 267 */ 268 int psCompareF32(const void * a, const void*b);268 int psCompareF32(const void *a, const void *b); 269 269 270 270 /** Compare function of psF64 data. … … 274 274 * than, equal to, or greater than the second. 275 275 */ 276 int psCompareF64(const void * a, const void*b);276 int psCompareF64(const void *a, const void *b); 277 277 278 278 /** Compare function of psS8 data. … … 282 282 * than, equal to, or less than the second. 283 283 */ 284 int psCompareDescendingS8(const void * a, const void*b);284 int psCompareDescendingS8(const void *a, const void *b); 285 285 286 286 /** Compare function of psS16 data. … … 290 290 * than, equal to, or less than the second. 291 291 */ 292 int psCompareDescendingS16(const void * a, const void*b);292 int psCompareDescendingS16(const void *a, const void *b); 293 293 294 294 /** Compare function of psS32 data. … … 298 298 * than, equal to, or less than the second. 299 299 */ 300 int psCompareDescendingS32(const void * a, const void*b);300 int psCompareDescendingS32(const void *a, const void *b); 301 301 302 302 /** Compare function of psS64 data. … … 306 306 * than, equal to, or less than the second. 307 307 */ 308 int psCompareDescendingS64(const void * a, const void*b);308 int psCompareDescendingS64(const void *a, const void *b); 309 309 310 310 /** Compare function of psU8 data. … … 314 314 * than, equal to, or less than the second. 315 315 */ 316 int psCompareDescendingU8(const void * a, const void*b);316 int psCompareDescendingU8(const void *a, const void *b); 317 317 318 318 /** Compare function of psU16 data. … … 322 322 * than, equal to, or less than the second. 323 323 */ 324 int psCompareDescendingU16(const void * a, const void*b);324 int psCompareDescendingU16(const void *a, const void *b); 325 325 326 326 /** Compare function of psU32 data. … … 330 330 * than, equal to, or lessg than the second. 331 331 */ 332 int psCompareDescendingU32(const void * a, const void*b);332 int psCompareDescendingU32(const void *a, const void *b); 333 333 334 334 /** Compare function of psU64 data. … … 338 338 * than, equal to, or lessg than the second. 339 339 */ 340 int psCompareDescendingU64(const void * a, const void*b);340 int psCompareDescendingU64(const void *a, const void *b); 341 341 342 342 /** Compare function of psF32 data. … … 346 346 * than, equal to, or lessg than the second. 347 347 */ 348 int psCompareDescendingF32(const void * a, const void*b);348 int psCompareDescendingF32(const void *a, const void *b); 349 349 350 350 /** Compare function of psF64 data. … … 354 354 * than, equal to, or lessg than the second. 355 355 */ 356 int psCompareDescendingF64(const void* a, const void* b); 357 358 356 int psCompareDescendingF64(const void *a, const void *b); 359 357 360 358 /// @} -
trunk/psLib/src/collections/psList.c
r1406 r1407 1 1 2 /** @file psList.c 2 3 * @brief Support for doubly linked lists … … 6 7 * @author Robert Daniel DeSonia, MHPCC 7 8 * 8 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-08-0 6 22:34:05$9 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-08-07 00:06:06 $ 10 11 * 11 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 16 #include <stdbool.h> 16 17 #include <stdio.h> 17 #include <pthread.h> // we need a mutex to make this stuff thread safe.18 #include <pthread.h> // we need a mutex to make this stuff thread safe. 18 19 19 20 #include "psError.h" … … 24 25 #include "psLogMsg.h" 25 26 26 #define ITER_INIT_HEAD ((void *)1) // next iteration should return head27 #define ITER_INIT_TAIL ((void *)2) // next iteration should return tail27 #define ITER_INIT_HEAD ((void *)1) // next iteration should return head 28 #define ITER_INIT_TAIL ((void *)2) // next iteration should return tail 28 29 29 30 // private functions. 30 static psListElem* listGetIterator(psList* list); 31 static int listGetIteratorIndex(psList* list); 32 static void listSetIterator(psList *list, int where, bool lockList); 33 static void listFree(psList *list); 34 31 static psListElem *listGetIterator(psList * list); 32 static int listGetIteratorIndex(psList * list); 33 static void listSetIterator(psList * list, int where, bool lockList); 34 static void listFree(psList * list); 35 35 36 36 psList *psListAlloc(void *data) 37 37 { 38 38 psList *list = psAlloc(sizeof(psList)); 39 p_psMemSetDeallocator(list,(psFreeFcn)listFree); 39 40 p_psMemSetDeallocator(list, (psFreeFcn) listFree); 40 41 41 42 list->size = 0; … … 44 45 list->iterIndex = PS_LIST_HEAD; 45 46 46 pthread_mutex_init(&(list->lock), NULL)47 pthread_mutex_init(&(list->lock), NULL) 47 48 ; 48 49 … … 54 55 } 55 56 56 static void listFree(psList * list)57 static void listFree(psList * list) 57 58 { 58 59 if (list == NULL) { … … 63 64 ; 64 65 65 for (psListElem *ptr = list->head; ptr != NULL;) {66 for (psListElem * ptr = list->head; ptr != NULL;) { 66 67 psListElem *next = ptr->next; 67 68 … … 80 81 } 81 82 82 bool psListAdd(psList * list, void *data, int where)83 { 84 psListElem *position;85 psListElem *elem;83 bool psListAdd(psList * list, void *data, int where) 84 { 85 psListElem *position; 86 psListElem *elem; 86 87 int cursorIndex = 0; 87 88 … … 95 96 96 97 if (where <= PS_LIST_UNKNOWN) { 97 /// XXX What is the better way to communicate this failure to the caller? 98 psLogMsg(__func__,PS_LOG_WARN, 99 "The given insert location (%i) for psListAdd is invalid.", 100 where); 98 // / XXX What is the better way to communicate this failure to the caller? 99 psLogMsg(__func__, PS_LOG_WARN, "The given insert location (%i) for psListAdd is invalid.", where); 101 100 return false; 102 101 } … … 108 107 109 108 if (where > 0 && where > list->size) { 110 psLogMsg(__func__,PS_LOG_WARN, 111 "Invalid index %d (only %d elements in psList); assuming tail.", 112 where, list->size); 109 psLogMsg(__func__, PS_LOG_WARN, 110 "Invalid index %d (only %d elements in psList); assuming tail.", where, list->size); 113 111 where = PS_LIST_TAIL; 114 112 } … … 138 136 139 137 if (position == NULL) { 140 psError(__func__,"%s failed to move cursor to specified location (%d)",__func__,where); 141 position = list->head; // since we no list->size != 0, this must be non-NULL 142 } 143 138 psError(__func__, "%s failed to move cursor to specified location (%d)", __func__, where); 139 position = list->head; // since we no list->size != 0, this must be non-NULL 140 } 144 141 // insert our new element in front of the given position 145 142 elem->prev = position->prev; … … 147 144 position->prev = elem; 148 145 149 if (elem->prev == NULL) { // must be front of list146 if (elem->prev == NULL) { // must be front of list 150 147 list->head = elem; 151 148 } else { … … 167 164 168 165 /*****************************************************************************/ 166 169 167 /* 170 168 * Remove an element from a list 171 169 */ 172 bool psListRemove(psList * list, void *data,int which)173 { 174 psListElem *elem = NULL; // element to remove170 bool psListRemove(psList * list, void *data, int which) 171 { 172 psListElem *elem = NULL; // element to remove 175 173 int cursorIndex = 0; 176 174 177 175 if (list == NULL) { 178 psError(__func__, "list parameter found to be NULL in %s",__func__);176 psError(__func__, "list parameter found to be NULL in %s", __func__); 179 177 return false; 180 178 } 181 182 179 // get exclusive access to list so that other threads will not get in the way. 183 180 pthread_mutex_lock(&list->lock) … … 187 184 // search list for the data item. 188 185 189 int i = 0; // index 190 for (psListElem *ptr = list->head; ptr != NULL; ptr = ptr->next) { 186 int i = 0; // index 187 188 for (psListElem * ptr = list->head; ptr != NULL; ptr = ptr->next) { 191 189 if (ptr->data == data) { 192 190 which = i; … … 201 199 } 202 200 } 203 204 201 // position the list's cursor to the desired location 205 listSetIterator(list, which,false);202 listSetIterator(list, which, false); 206 203 elem = listGetIterator(list); 207 204 cursorIndex = listGetIteratorIndex(list); 208 205 209 206 if (elem == NULL) { 210 psError(__func__, "Couldn't position to given index (%d) to remove element from list.", which);207 psError(__func__, "Couldn't position to given index (%d) to remove element from list.", which); 211 208 return false; 212 209 } … … 214 211 list->size--; 215 212 216 if (elem->prev == NULL) { // head of list?213 if (elem->prev == NULL) { // head of list? 217 214 list->head = elem->next; 218 215 } else { … … 220 217 } 221 218 222 if (elem->next == NULL) { // tail of list?219 if (elem->next == NULL) { // tail of list? 223 220 list->tail = elem->prev; 224 221 … … 246 243 } 247 244 248 void psListSetIterator(psList * list, int where)249 { 250 listSetIterator(list, where,true);251 } 252 253 void listSetIterator(psList * list, int where, bool lockList)254 { 255 psListElem *cursor;245 void psListSetIterator(psList * list, int where) 246 { 247 listSetIterator(list, where, true); 248 } 249 250 void listSetIterator(psList * list, int where, bool lockList) 251 { 252 psListElem *cursor; 256 253 int position; 257 254 258 255 if (list == NULL) { 259 psError(__func__, "Unexpected null pointer for psList parameter (%s:%d).",__FILE__,__LINE__);256 psError(__func__, "Unexpected null pointer for psList parameter (%s:%d).", __FILE__, __LINE__); 260 257 return; 261 258 } … … 291 288 if (cursor != NULL) { 292 289 list->iter = cursor->prev; 293 list->iterIndex = position -1;290 list->iterIndex = position - 1; 294 291 } 295 292 break; … … 301 298 if (cursor != NULL) { 302 299 list->iter = cursor->next; 303 list->iterIndex = position +1;300 list->iterIndex = position + 1; 304 301 } 305 302 break; … … 309 306 310 307 default: 311 if (where <= PS_LIST_HEAD) { // bascially same as PS_LIST_UNKNOWN above312 psError(__func__, "Can't move to an unknown position. Not moving the iterator position.");308 if (where <= PS_LIST_HEAD) { // bascially same as PS_LIST_UNKNOWN above 309 psError(__func__, "Can't move to an unknown position. Not moving the iterator position."); 313 310 } else { 314 311 cursor = listGetIterator(list); 315 if (cursor == NULL) { // reset the iterator if it is invalid312 if (cursor == NULL) { // reset the iterator if it is invalid 316 313 list->iter = ITER_INIT_HEAD; 317 314 list->iterIndex = 0; … … 321 318 322 319 if (where < position) { 323 int diff = position-where; 324 for (int count=0;count < diff; count++) { 325 listSetIterator(list,PS_LIST_PREVIOUS,false); 320 int diff = position - where; 321 322 for (int count = 0; count < diff; count++) { 323 listSetIterator(list, PS_LIST_PREVIOUS, false); 326 324 } 327 325 } else { 328 int diff = where-position; 329 for (int count=0;count < diff; count++) { 330 listSetIterator(list,PS_LIST_NEXT,false); 326 int diff = where - position; 327 328 for (int count = 0; count < diff; count++) { 329 listSetIterator(list, PS_LIST_NEXT, false); 331 330 } 332 331 } … … 341 340 } 342 341 343 psListElem * listGetIterator(psList* list)342 psListElem *listGetIterator(psList * list) 344 343 { 345 344 if (list == NULL) { … … 349 348 if (list->iter == ITER_INIT_HEAD) { 350 349 return list->head; 351 } else 352 if (list->iter == ITER_INIT_TAIL) { 353 return list->tail; 354 } else { 355 return list->iter; 356 } 357 } 358 359 int listGetIteratorIndex(psList* list) 350 } else if (list->iter == ITER_INIT_TAIL) { 351 return list->tail; 352 } else { 353 return list->iter; 354 } 355 } 356 357 int listGetIteratorIndex(psList * list) 360 358 { 361 359 if (list->iter == ITER_INIT_HEAD) { 362 360 return 0; 363 } else 364 if (list->iter == ITER_INIT_TAIL) { 365 return list->size-1; 366 } else { 367 return list->iterIndex; 368 } 369 } 370 371 void* psListGet(psList* list,int which) 372 { 373 psListElem* element; 374 375 psListSetIterator(list,which); 361 } else if (list->iter == ITER_INIT_TAIL) { 362 return list->size - 1; 363 } else { 364 return list->iterIndex; 365 } 366 } 367 368 void *psListGet(psList * list, int which) 369 { 370 psListElem *element; 371 372 psListSetIterator(list, which); 376 373 element = listGetIterator(list); 377 374 … … 382 379 } 383 380 } 381 384 382 /* 385 383 * and now return the previous/next element of the list 386 384 */ 387 void *psListGetNext(psList * list)385 void *psListGetNext(psList * list) 388 386 { 389 387 return psListGet(list, PS_LIST_NEXT); 390 388 } 391 389 392 void *psListGetPrevious(psList * list)390 void *psListGetPrevious(psList * list) 393 391 { 394 392 return psListGet(list, PS_LIST_PREVIOUS); 395 393 } 396 394 397 void *psListGetCurrent(psList * list)395 void *psListGetCurrent(psList * list) 398 396 { 399 397 return psListGet(list, PS_LIST_CURRENT); … … 403 401 * Convert a psList to/from a psVoidPtrArray 404 402 */ 405 psArray * psListToArray(psList* restrict list)406 { 407 psListElem *ptr;403 psArray *psListToArray(psList * restrict list) 404 { 405 psListElem *ptr; 408 406 unsigned int n; 409 psArray *restrict arr;407 psArray *restrict arr; 410 408 411 409 if (list == NULL) { … … 431 429 } 432 430 433 psList * psArrayToList(psArray* arr)431 psList *psArrayToList(psArray * arr) 434 432 { 435 433 unsigned int n; 436 psList * list;// list of elements434 psList *list; // list of elements 437 435 438 436 if (arr == NULL) { … … 443 441 n = arr->n; 444 442 for (int i = 0; i < n; i++) { 445 psListAdd(list, arr->data[i],PS_LIST_TAIL);443 psListAdd(list, arr->data[i], PS_LIST_TAIL); 446 444 } 447 445 … … 449 447 } 450 448 451 452 psList* psListSort(psList* list, psComparePtrFcn compare) 453 { 454 psArray* arr; 449 psList *psListSort(psList * list, psComparePtrFcn compare) 450 { 451 psArray *arr; 452 455 453 if (list == NULL) { 456 454 return NULL; 457 455 } 458 459 456 // convert to indexable vector for use by qsort. 460 457 arr = psListToArray(list); 461 458 psFree(list); 462 459 463 arr = psArraySort(arr, compare);460 arr = psArraySort(arr, compare); 464 461 465 462 // convert back to linked list -
trunk/psLib/src/collections/psList.h
r1228 r1407 1 1 #if !defined(PS_LIST_H) 2 # define PS_LIST_H2 # define PS_LIST_H 3 3 4 4 /** @file psList.h … … 10 10 * @ingroup LinkedList 11 11 * 12 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-0 7-15 22:18:02$12 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-08-07 00:06:06 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 16 16 */ 17 17 18 # include <pthread.h> // we need a mutex to make this stuff thread safe.19 # include <stdbool.h> // we use the bool type.18 # include <pthread.h> // we need a mutex to make this stuff thread safe. 19 # include <stdbool.h> // we use the bool type. 20 20 21 # include "psCompare.h"22 # include "psArray.h"21 # include "psCompare.h" 22 # include "psArray.h" 23 23 24 24 /** @addtogroup LinkedList … … 33 33 */ 34 34 enum { 35 PS_LIST_HEAD = 0, ///< at head36 PS_LIST_TAIL = -1, ///< at tail37 PS_LIST_PREVIOUS = -2, ///< previous element38 PS_LIST_CURRENT = -3, ///< current element39 PS_LIST_NEXT = -4, ///< next element40 PS_LIST_UNKNOWN = -5 ///< unknown position (should be last in enum list)35 PS_LIST_HEAD = 0, // /< at head 36 PS_LIST_TAIL = -1, // /< at tail 37 PS_LIST_PREVIOUS = -2, // /< previous element 38 PS_LIST_CURRENT = -3, // /< current element 39 PS_LIST_NEXT = -4, // /< next element 40 PS_LIST_UNKNOWN = -5 // /< unknown position (should be last in enum list) 41 41 }; 42 42 … … 44 44 typedef struct psListElem 45 45 { 46 struct psListElem *prev; ///< previous link in list47 struct psListElem *next; ///< next link in list48 void *data; ///< real data item46 struct psListElem *prev; // /< previous link in list 47 struct psListElem *next; // /< next link in list 48 void *data; // /< real data item 49 49 } 50 50 psListElem; … … 57 57 typedef struct 58 58 { 59 unsigned int size; ///< number of elements on list60 psListElem * head; ///< first element on list (may be NULL)61 psListElem * tail; ///< last element on list (may be NULL)62 psListElem * iter; ///< iteration cursor63 unsigned int iterIndex; ///< the numeric position of the iteration cursor in the list64 pthread_mutex_t lock; ///< mutex to lock a node during changes59 unsigned int size; // /< number of elements on list 60 psListElem *head; // /< first element on list (may be NULL) 61 psListElem *tail; // /< last element on list (may be NULL) 62 psListElem *iter; // /< iteration cursor 63 unsigned int iterIndex; // /< the numeric position of the iteration cursor in the list 64 pthread_mutex_t lock; // /< mutex to lock a node during changes 65 65 } 66 66 psList; … … 70 70 * @return psList* A new psList object. 71 71 */ 72 psList* psListAlloc( 73 void *data 74 ///< initial data item; may be NULL if no an empty psList is desired 75 ) 72 psList *psListAlloc(void *data 73 // /< initial data item; may be NULL if no an empty psList is desired 74 ) 76 75 ; 77 76 … … 81 80 * NULL, the return value will also be NULL. 82 81 */ 83 bool psListAdd( 84 psList* restrict list, ///< list to add to (if NULL, nothing is done) 85 void* data, ///< data item to add. If NULL, list is not modified. 86 int where ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location. 87 ); 82 bool psListAdd(psList * restrict list, // /< list to add to (if NULL, nothing is done) 83 void *data, // /< data item to add. If NULL, list is not modified. 84 int where // /< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location. 85 ); 88 86 89 87 /** Remove an item from a list. If which parameter is PS_LIST_UNKNOWN, … … 91 89 * @return bool TRUE if element is successfully removed, otherwise FALSE. 92 90 */ 93 bool psListRemove( 94 psList* restrict list, 95 ///< list to remove element from 96 void *data, 97 ///< if which is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored. 98 int which 99 ///< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV, or numbered location. 100 ); 91 bool psListRemove(psList * restrict list, 92 // /< list to remove element from 93 void *data, 94 // /< if which is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored. 95 int which 96 // /< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV, or numbered location. 97 ); 101 98 102 99 /** Retrieve an item from a list. … … 107 104 * NULL is returned. 108 105 */ 109 void* psListGet( 110 psList* restrict list, ///< list to retrieve element from 111 int which ///< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN 112 ); 106 void *psListGet(psList * restrict list, // /< list to retrieve element from 107 int which // /< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN 108 ); 113 109 114 110 /** Set the iterator of the list to a given position. If where is invalid the … … 116 112 * 117 113 */ 118 void psListSetIterator( 119 psList* restrict list, ///< list to retrieve element from 120 int where ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL 121 ); 114 void psListSetIterator(psList * restrict list, // /< list to retrieve element from 115 int where // /< index number, PS_LIST_HEAD, or PS_LIST_TAIL 116 ); 122 117 123 118 /** Get next element relative to the iterator. This also moves the iterator to … … 128 123 * parameter was NULL. 129 124 */ 130 void* psListGetNext( 131 psList* restrict list ///< list to retrieve element from 132 ); 125 void *psListGetNext(psList * restrict list // /< list to retrieve element from 126 ); 133 127 134 128 /** Get current element according to the psList's iterator cursor. This does … … 139 133 * iterator is not valid or list parameter was NULL. 140 134 */ 141 void* psListGetCurrent( 142 psList* restrict list ///< list to retrieve element from 143 ); 135 void *psListGetCurrent(psList * restrict list // /< list to retrieve element from 136 ); 144 137 145 138 /** Get previous element relative to list's iterator. This also moves the … … 150 143 * parameter was NULL. 151 144 */ 152 void* psListGetPrevious( 153 psList* restrict list ///< list to retrieve element from 154 ); 145 void *psListGetPrevious(psList * restrict list // /< list to retrieve element from 146 ); 155 147 156 148 /** Convert a linked list to an array … … 159 151 * or NULL if the given dlist parameter is NULL. 160 152 */ 161 psArray* psListToArray( 162 psList *dlist ///< List to convert 163 ); 153 psArray *psListToArray(psList * dlist // /< List to convert 154 ); 164 155 165 156 /** Convert array to a doubly-linked list … … 168 159 * or NULL is the given arr parameter is NULL. 169 160 */ 170 psList* psArrayToList( 171 psArray* arr ///< vector to convert 172 ); 161 psList *psArrayToList(psArray * arr // /< vector to convert 162 ); 173 163 174 psList * psListSort(psList* list, psComparePtrFcn compare);164 psList *psListSort(psList * list, psComparePtrFcn compare); 175 165 176 166 /// @} End of DataGroup Functions 177 167 178 168 #endif 179 -
trunk/psLib/src/collections/psMetadata.c
r1406 r1407 1 1 2 /** @file psMetadata.c 2 3 * … … 11 12 * @author Ross Harman, MHPCC 12 13 * 13 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-08-0 6 22:34:05$14 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-08-07 00:06:06 $ 15 16 * 16 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 19 19 20 /******************************************************************************/ 21 20 22 /* INCLUDE FILES */ 23 21 24 /******************************************************************************/ 22 25 #include<stdio.h> … … 34 37 #include "psString.h" 35 38 36 37 39 /******************************************************************************/ 40 38 41 /* DEFINE STATEMENTS */ 42 39 43 /******************************************************************************/ 40 44 … … 56 60 57 61 /******************************************************************************/ 62 58 63 /* TYPE DEFINITIONS */ 64 59 65 /******************************************************************************/ 60 66 … … 62 68 63 69 /*****************************************************************************/ 70 64 71 /* GLOBAL VARIABLES */ 72 65 73 /*****************************************************************************/ 66 74 … … 68 76 69 77 /*****************************************************************************/ 78 70 79 /* FILE STATIC VARIABLES */ 80 71 81 /*****************************************************************************/ 72 82 … … 74 84 75 85 /*****************************************************************************/ 86 76 87 /* FUNCTION IMPLEMENTATION - LOCAL */ 77 /*****************************************************************************/ 78 static void metadataItemFree( psMetadataItem *metadataItem ) 88 89 /*****************************************************************************/ 90 static void metadataItemFree(psMetadataItem * metadataItem) 79 91 { 80 92 psMetadataType type; … … 82 94 type = metadataItem->type; 83 95 84 if (metadataItem == NULL) {85 return ;86 } 87 88 psFree( metadataItem->name);89 psFree( metadataItem->comment);90 psFree( metadataItem->items);91 92 if (type == PS_META_STR ||96 if (metadataItem == NULL) { 97 return; 98 } 99 100 psFree(metadataItem->name); 101 psFree(metadataItem->comment); 102 psFree(metadataItem->items); 103 104 if (type == PS_META_STR || 93 105 type == PS_META_IMG || 94 type == PS_META_JPEG || 95 type == PS_META_PNG || 96 type == PS_META_ASTROM || 97 type == PS_META_UNKNOWN) { 98 psFree( metadataItem->data.V ); 99 } 100 } 101 102 static void metadataFree( psMetadata *metadata ) 103 { 104 if(metadata == NULL) { 105 return ; 106 } 107 psFree( metadata->list ); 108 psFree( metadata->table ); 109 } 110 111 /*****************************************************************************/ 106 type == PS_META_JPEG || type == PS_META_PNG || type == PS_META_ASTROM || type == PS_META_UNKNOWN) { 107 psFree(metadataItem->data.V); 108 } 109 } 110 111 static void metadataFree(psMetadata * metadata) 112 { 113 if (metadata == NULL) { 114 return; 115 } 116 psFree(metadata->list); 117 psFree(metadata->table); 118 } 119 120 /*****************************************************************************/ 121 112 122 /* FUNCTION IMPLEMENTATION - PUBLIC */ 113 /*****************************************************************************/ 114 115 psMetadataItem *psMetadataItemAlloc( const char *name, psMetadataType type, const char *comment, ... ) 123 124 /*****************************************************************************/ 125 126 psMetadataItem *psMetadataItemAlloc(const char *name, psMetadataType type, const char *comment, ...) 116 127 { 117 128 va_list argPtr; … … 119 130 120 131 // Get the variable list parameters to pass to allocation function 121 va_start( argPtr, comment);132 va_start(argPtr, comment); 122 133 123 134 // Call metadata item allocation 124 metadataItem = psMetadataItemAllocV( name, type, comment, argPtr);135 metadataItem = psMetadataItemAllocV(name, type, comment, argPtr); 125 136 126 137 // Clean up stack after variable arguement has been used 127 va_end( argPtr);138 va_end(argPtr); 128 139 129 140 return metadataItem; 130 141 } 131 142 132 psMetadataItem *psMetadataItemAllocV( const char *name, psMetadataType type, const char *comment, va_list argPtr )133 { 134 psMetadataItem * metadataItem = NULL; 135 136 if(name == NULL) { 137 psError( __func__, "Null value for name not allowed" );138 return NULL;139 }140 143 psMetadataItem *psMetadataItemAllocV(const char *name, psMetadataType type, const char *comment, 144 va_list argPtr) 145 { 146 psMetadataItem *metadataItem = NULL; 147 148 if (name == NULL) { 149 psError(__func__, "Null value for name not allowed"); 150 return NULL; 151 } 141 152 // Allocate metadata item 142 metadataItem = ( psMetadataItem * ) psAlloc( sizeof( psMetadataItem ) ); 143 if(metadataItem == NULL) { 144 psAbort( __func__, "Failed to allocate memory" ); 145 } 146 153 metadataItem = (psMetadataItem *) psAlloc(sizeof(psMetadataItem)); 154 if (metadataItem == NULL) { 155 psAbort(__func__, "Failed to allocate memory"); 156 } 147 157 // Set deallocator 148 p_psMemSetDeallocator( metadataItem, ( psFreeFcn ) metadataItemFree);158 p_psMemSetDeallocator(metadataItem, (psFreeFcn) metadataItemFree); 149 159 150 160 // Allocate and set metadata item comment 151 metadataItem->comment = ( char * ) psAlloc( sizeof( char ) * MAX_STRING_LENGTH);152 if (comment == NULL) {161 metadataItem->comment = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH); 162 if (comment == NULL) { 153 163 // Per SDRS, null isn't allowed, must use "" instead 154 strncpy( metadataItem->comment, "", MAX_STRING_LENGTH);164 strncpy(metadataItem->comment, "", MAX_STRING_LENGTH); 155 165 } else { 156 strncpy( metadataItem->comment, comment, MAX_STRING_LENGTH);166 strncpy(metadataItem->comment, comment, MAX_STRING_LENGTH); 157 167 } 158 168 159 169 // Set metadata item unique id 160 *( int* ) ( &metadataItem->id) = ++metadataId;170 *(int *)(&metadataItem->id) = ++metadataId; 161 171 162 172 // Set metadata item type … … 164 174 165 175 // Set metadata item value 166 switch (type) {176 switch (type) { 167 177 case PS_META_BOOL: 168 metadataItem->data.B = ( bool ) va_arg( argPtr, int ); 178 metadataItem->data.B = (bool) va_arg(argPtr, int); 179 169 180 break; 170 181 case PS_META_S32: 171 metadataItem->data.S32 = va_arg( argPtr, psS32);182 metadataItem->data.S32 = va_arg(argPtr, psS32); 172 183 break; 173 184 case PS_META_F32: 174 metadataItem->data.F32 = ( psF32 ) va_arg( argPtr, psF64);185 metadataItem->data.F32 = (psF32) va_arg(argPtr, psF64); 175 186 break; 176 187 case PS_META_F64: 177 metadataItem->data.F64 = va_arg( argPtr, psF64);188 metadataItem->data.F64 = va_arg(argPtr, psF64); 178 189 break; 179 190 case PS_META_STR: 180 metadataItem->data.V = psStringNCopy( va_arg( argPtr, char* ), MAX_STRING_LENGTH ); 191 metadataItem->data.V = psStringNCopy(va_arg(argPtr, char *), MAX_STRING_LENGTH); 192 181 193 break; 182 194 case PS_META_IMG: … … 186 198 case PS_META_UNKNOWN: 187 199 default: 188 psError( __func__, "Invalid psMetadataType: %d", type);200 psError(__func__, "Invalid psMetadataType: %d", type); 189 201 } 190 202 191 203 // Allocate and set metadata item name 192 metadataItem->name = ( char * ) psAlloc( sizeof( char ) * MAX_STRING_LENGTH);193 vsprintf( metadataItem->name, name, argPtr);204 metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH); 205 vsprintf(metadataItem->name, name, argPtr); 194 206 195 207 // Allocate metadata items with same name. 196 metadataItem->items = psListAlloc( NULL);208 metadataItem->items = psListAlloc(NULL); 197 209 198 210 return metadataItem; 199 211 } 200 212 201 psMetadata *psMetadataAlloc( void)202 { 203 psList * list = NULL;213 psMetadata *psMetadataAlloc(void) 214 { 215 psList *list = NULL; 204 216 psHash *table = NULL; 205 217 psMetadata *metadata = NULL; 206 218 207 219 // Allocate metadata 208 metadata = ( psMetadata * ) psAlloc( sizeof( psMetadata ) ); 209 if(metadata == NULL) { 210 psAbort( __func__, "Failed to allocate metadata" ); 211 } 212 220 metadata = (psMetadata *) psAlloc(sizeof(psMetadata)); 221 if (metadata == NULL) { 222 psAbort(__func__, "Failed to allocate metadata"); 223 } 213 224 // Set deallocator 214 p_psMemSetDeallocator( metadata, ( psFreeFcn ) metadataFree);225 p_psMemSetDeallocator(metadata, (psFreeFcn) metadataFree); 215 226 216 227 // Allocate metadata's internal containers 217 list = ( psList * ) psListAlloc( NULL);218 if (list == NULL) {219 psAbort( __func__, "Failed to allocate list");220 } 221 222 table = ( psHash * ) psHashAlloc( 10);223 if (table == NULL) {224 psAbort( __func__, "Failed to allocate table");228 list = (psList *) psListAlloc(NULL); 229 if (list == NULL) { 230 psAbort(__func__, "Failed to allocate list"); 231 } 232 233 table = (psHash *) psHashAlloc(10); 234 if (table == NULL) { 235 psAbort(__func__, "Failed to allocate table"); 225 236 } 226 237 … … 231 242 } 232 243 233 bool psMetadataAddItem( psMetadata *restrict md, int where, psMetadataItem *restrict metadataItem)234 { 235 char * key = NULL;244 bool psMetadataAddItem(psMetadata * restrict md, int where, psMetadataItem * restrict metadataItem) 245 { 246 char *key = NULL; 236 247 psHash *mdTable = NULL; 237 248 psList *mdList = NULL; … … 239 250 psMetadataType type = PS_META_ITEM_SET; 240 251 241 if (md == NULL) {242 psError( __func__, "Null metadata collection not allowed");243 return false; 244 } 245 246 if (metadataItem == NULL) {247 psError( __func__, "Null metadata item not allowed");252 if (md == NULL) { 253 psError(__func__, "Null metadata collection not allowed"); 254 return false; 255 } 256 257 if (metadataItem == NULL) { 258 psError(__func__, "Null metadata item not allowed"); 248 259 return false; 249 260 } … … 252 263 253 264 mdTable = md->table; 254 if (mdTable == NULL) {255 psError( __func__, "Null metadata table not allowed");256 return false; 257 } 258 259 mdList = md->list; 260 if (mdList == NULL) {261 psError( __func__, "Null metadata list not allowed");265 if (mdTable == NULL) { 266 psError(__func__, "Null metadata table not allowed"); 267 return false; 268 } 269 270 mdList = md->list; 271 if (mdList == NULL) { 272 psError(__func__, "Null metadata list not allowed"); 262 273 return false; 263 274 } 264 275 265 276 key = metadataItem->name; 266 if(key == NULL) { 267 psError( __func__, "Null key item not allowed" ); 268 return false; 269 } 270 277 if (key == NULL) { 278 psError(__func__, "Null key item not allowed"); 279 return false; 280 } 271 281 // Check if key is already in table 272 value = ( psMetadataItem* ) psHashLookup( mdTable, key);273 if (value != NULL && type != PS_META_ITEM_SET) {282 value = (psMetadataItem *) psHashLookup(mdTable, key); 283 if (value != NULL && type != PS_META_ITEM_SET) { 274 284 275 285 // The key was found and the new metadata item is a leaf node (its type isn't PS_META_ITEM_SET), so 276 286 // add the new metadata item to hash as a child of the existing metadata item folder node. 277 if(!psListAdd( value->items, metadataItem, where )) { 278 psError( __func__, "Couldn't add metadata item to items list. Name: %s", 279 metadataItem->name ); 287 if (!psListAdd(value->items, metadataItem, where)) { 288 psError(__func__, "Couldn't add metadata item to items list. Name: %s", metadataItem->name); 280 289 return false; 281 290 } 282 } else 283 if(value != NULL) { 284 285 // The key was found and the new metadata item is a folder node. Don't add new metadata item, since 286 // it will wipe out existing node. 287 psError( __func__, "Metadata already exists in metadata collection. Item not added. Name: %s", 288 metadataItem->name ); 291 } else if (value != NULL) { 292 293 // The key was found and the new metadata item is a folder node. Don't add new metadata item, since 294 // it will wipe out existing node. 295 psError(__func__, "Metadata already exists in metadata collection. Item not added. Name: %s", 296 metadataItem->name); 297 return false; 298 } else { 299 300 // Duplicate key not found. Add new metadata item to metadata collection's hash 301 if (!psHashAdd(mdTable, key, metadataItem)) { 302 psError(__func__, "Couldn't add metadata item to metadata collection table. Name: %s", 303 metadataItem->name); 289 304 return false; 290 } else { 291 292 // Duplicate key not found. Add new metadata item to metadata collection's hash 293 if(!psHashAdd( mdTable, key, metadataItem )) { 294 psError( __func__, "Couldn't add metadata item to metadata collection table. Name: %s", 295 metadataItem->name ); 296 return false; 297 } 298 } 305 } 306 } 299 307 300 308 // Add all items to metadata collection's list, even if they have the same metadata item names 301 if (!psListAdd( md->list, metadataItem, where)) {302 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",303 metadataItem->name);309 if (!psListAdd(md->list, metadataItem, where)) { 310 psError(__func__, "Couldn't add metadata item to metadata collection list. Name: %s", 311 metadataItem->name); 304 312 return false; 305 313 } … … 308 316 } 309 317 310 bool psMetadataAdd( psMetadata *restrict md, int where, const char *name, psMetadataType type,311 const char *comment, ...)318 bool psMetadataAdd(psMetadata * restrict md, int where, const char *name, psMetadataType type, 319 const char *comment, ...) 312 320 { 313 321 va_list argPtr; 314 322 psMetadataItem *metadataItem = NULL; 315 323 316 va_start( argPtr, comment);317 metadataItem = psMetadataItemAllocV( name, type, comment, argPtr);318 va_end( argPtr);319 320 if (!psMetadataAddItem( md, where, metadataItem)) {321 psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",322 metadataItem->name);323 psFree( metadataItem);324 return false; 325 } 326 327 // Decrement reference count, since the metadata item is now in metadata collection and no longer neededhere328 psMemDecrRefCounter( metadataItem);324 va_start(argPtr, comment); 325 metadataItem = psMetadataItemAllocV(name, type, comment, argPtr); 326 va_end(argPtr); 327 328 if (!psMetadataAddItem(md, where, metadataItem)) { 329 psError(__func__, "Couldn't add metadata item to metadata collection list. Name: %s", 330 metadataItem->name); 331 psFree(metadataItem); 332 return false; 333 } 334 // Decrement reference count, since the metadata item is now in metadata collection and no longer needed 335 // here 336 psMemDecrRefCounter(metadataItem); 329 337 330 338 return true; 331 339 } 332 340 333 bool psMetadataRemove( psMetadata *restrict md, int where, const char *restrict key)341 bool psMetadataRemove(psMetadata * restrict md, int where, const char *restrict key) 334 342 { 335 343 int numChildren = 0; … … 340 348 341 349 mdList = md->list; 342 if (mdList == NULL) {343 psError( __func__, "Null metadata list not allowed");350 if (mdList == NULL) { 351 psError(__func__, "Null metadata list not allowed"); 344 352 return false; 345 353 } 346 354 347 355 mdTable = md->table; 348 if(mdTable == NULL) { 349 psError( __func__, "Null metadata table not allowed" ); 350 return false; 351 } 352 356 if (mdTable == NULL) { 357 psError(__func__, "Null metadata table not allowed"); 358 return false; 359 } 353 360 // Select removal by key or index 354 if (key != NULL) {361 if (key != NULL) { 355 362 356 363 // Remove by key name 357 entry = ( psMetadataItem* ) psHashLookup( mdTable, key);358 if (entry == NULL) {359 psError( __func__, "Couldn't find metadata item remove. Name: %s", key);364 entry = (psMetadataItem *) psHashLookup(mdTable, key); 365 if (entry == NULL) { 366 psError(__func__, "Couldn't find metadata item remove. Name: %s", key); 360 367 return false; 361 368 } 362 369 363 370 numChildren = entry->items->size; 364 if (entry->type == PS_META_ITEM_SET && numChildren > 0) {371 if (entry->type == PS_META_ITEM_SET && numChildren > 0) { 365 372 366 373 // Table entry has children. Entry and children must be removed from metadata collection's list 367 psListSetIterator( mdList, PS_LIST_HEAD);368 entryChild = psListGetCurrent( mdList);369 while (entryChild != NULL) {370 if (!psListRemove( entry->items, entryChild, PS_LIST_UNKNOWN)) {371 psError( __func__, "Couldn't remove metadata item from list. Name: %s", key);374 psListSetIterator(mdList, PS_LIST_HEAD); 375 entryChild = psListGetCurrent(mdList); 376 while (entryChild != NULL) { 377 if (!psListRemove(entry->items, entryChild, PS_LIST_UNKNOWN)) { 378 psError(__func__, "Couldn't remove metadata item from list. Name: %s", key); 372 379 return false; 373 380 } 374 entryChild = psListGetNext( entry->items);381 entryChild = psListGetNext(entry->items); 375 382 } 376 383 } 377 378 384 // Remove entry from metadata collection's list 379 if (!psListRemove( mdList, entry, PS_LIST_UNKNOWN)) {380 psError( __func__, "Couldn't remove metadata item from list. Name: %s", key);385 if (!psListRemove(mdList, entry, PS_LIST_UNKNOWN)) { 386 psError(__func__, "Couldn't remove metadata item from list. Name: %s", key); 381 387 return false; 382 388 } 383 384 389 // Remove entry from metadata collection's table 385 if (!psHashRemove( mdTable, key)) {386 psError( __func__, "Couldn't remove metadata item from table. Name: %s", key);390 if (!psHashRemove(mdTable, key)) { 391 psError(__func__, "Couldn't remove metadata item from table. Name: %s", key); 387 392 return false; 388 393 } … … 390 395 391 396 // Remove by index 392 entry = psListGet( mdList, where);393 if (entry == NULL) {394 psError( __func__, "Couldn't find metadata item from list. Index: %d", where);397 entry = psListGet(mdList, where); 398 if (entry == NULL) { 399 psError(__func__, "Couldn't find metadata item from list. Index: %d", where); 395 400 return false; 396 401 } 397 402 398 403 key = entry->name; 399 if (key == NULL) {400 psError( __func__, "Null key name not allowed. Index: %d", where);404 if (key == NULL) { 405 psError(__func__, "Null key name not allowed. Index: %d", where); 401 406 return false; 402 407 } 403 404 408 // Use recursive remove, now that key is known 405 psMetadataRemove( md, PS_LIST_UNKNOWN, key);409 psMetadataRemove(md, PS_LIST_UNKNOWN, key); 406 410 } 407 411 … … 409 413 } 410 414 411 psMetadataItem *psMetadataLookup( psMetadata *restrict md, const char *restrict key)412 { 413 psHash * mdTable = NULL;415 psMetadataItem *psMetadataLookup(psMetadata * restrict md, const char *restrict key) 416 { 417 psHash *mdTable = NULL; 414 418 psMetadataItem *entry = NULL; 415 419 416 420 mdTable = md->table; 417 if (mdTable == NULL) {418 psError( __func__, "Null metadata table not allowed");419 return NULL; 420 } 421 422 if (key == NULL) {423 psError( __func__, "Null key name not allowed");424 return NULL; 425 } 426 427 entry = ( psMetadataItem* ) psHashLookup( mdTable, key);428 if (entry == NULL) {429 psError( __func__, "Could not find metadata item with given key. Key: %s", key);421 if (mdTable == NULL) { 422 psError(__func__, "Null metadata table not allowed"); 423 return NULL; 424 } 425 426 if (key == NULL) { 427 psError(__func__, "Null key name not allowed"); 428 return NULL; 429 } 430 431 entry = (psMetadataItem *) psHashLookup(mdTable, key); 432 if (entry == NULL) { 433 psError(__func__, "Could not find metadata item with given key. Key: %s", key); 430 434 return NULL; 431 435 } … … 434 438 } 435 439 436 psMetadataItem *psMetadataGet( psMetadata *restrict md, int where)437 { 438 psList * mdList = NULL;440 psMetadataItem *psMetadataGet(psMetadata * restrict md, int where) 441 { 442 psList *mdList = NULL; 439 443 psMetadataItem *entry = NULL; 440 444 441 445 mdList = md->list; 442 if (mdList == NULL) {443 psError( __func__, "Null metadata list not allowed");444 return NULL; 445 } 446 447 entry = ( psMetadataItem* ) psListGet( mdList, where);448 if (entry == NULL) {449 psError( __func__, "Couldn't find metadata item with given index. Index: %d", where);446 if (mdList == NULL) { 447 psError(__func__, "Null metadata list not allowed"); 448 return NULL; 449 } 450 451 entry = (psMetadataItem *) psListGet(mdList, where); 452 if (entry == NULL) { 453 psError(__func__, "Couldn't find metadata item with given index. Index: %d", where); 450 454 return NULL; 451 455 } … … 454 458 } 455 459 456 bool psMetadataSetIterator( psMetadata *restrict md, int where)457 { 458 psList * mdList = NULL;459 460 mdList = md->list; 461 if (mdList == NULL) {462 psError( __func__, "Null metadata list not allowed");463 return false; 464 } 465 466 psListSetIterator( mdList, where);460 bool psMetadataSetIterator(psMetadata * restrict md, int where) 461 { 462 psList *mdList = NULL; 463 464 mdList = md->list; 465 if (mdList == NULL) { 466 psError(__func__, "Null metadata list not allowed"); 467 return false; 468 } 469 470 psListSetIterator(mdList, where); 467 471 468 472 return true; 469 473 } 470 474 471 psMetadataItem *psMetadataGetNext( psMetadata *restrict md, const char *restrict match, int which)472 { 473 psList * mdList = NULL;475 psMetadataItem *psMetadataGetNext(psMetadata * restrict md, const char *restrict match, int which) 476 { 477 psList *mdList = NULL; 474 478 psMetadataItem *entry = NULL; 475 479 476 480 mdList = md->list; 477 if (mdList == NULL) {478 psError( __func__, "Null metadata list not allowed");479 return NULL; 480 } 481 482 mdList = md->list; 483 if (mdList == NULL) {484 psError( __func__, "Null metadata list not allowed");485 return NULL; 486 } 487 488 psListSetIterator( mdList, which);489 entry = psListGetCurrent( mdList);490 while (entry != NULL) {491 if (!strncmp( match, entry->name, strlen( match ))) {481 if (mdList == NULL) { 482 psError(__func__, "Null metadata list not allowed"); 483 return NULL; 484 } 485 486 mdList = md->list; 487 if (mdList == NULL) { 488 psError(__func__, "Null metadata list not allowed"); 489 return NULL; 490 } 491 492 psListSetIterator(mdList, which); 493 entry = psListGetCurrent(mdList); 494 while (entry != NULL) { 495 if (!strncmp(match, entry->name, strlen(match))) { 492 496 493 497 // Match found 494 498 return entry; 495 499 } 496 entry = psListGetNext( mdList);500 entry = psListGetNext(mdList); 497 501 } 498 502 499 503 // Match not found 500 if (entry == NULL) {501 psError( __func__, "Couldn't find metadata item with given match. Match: %s", match);504 if (entry == NULL) { 505 psError(__func__, "Couldn't find metadata item with given match. Match: %s", match); 502 506 } 503 507 … … 505 509 } 506 510 507 psMetadataItem *psMetadataGetPrevious( psMetadata *restrict md, const char *restrict match, int which)508 { 509 psList * mdList = NULL;511 psMetadataItem *psMetadataGetPrevious(psMetadata * restrict md, const char *restrict match, int which) 512 { 513 psList *mdList = NULL; 510 514 psMetadataItem *entry = NULL; 511 515 512 516 mdList = md->list; 513 if (mdList == NULL) {514 psError( __func__, "Null metadata list not allowed");515 return NULL; 516 } 517 518 mdList = md->list; 519 if (mdList == NULL) {520 psError( __func__, "Null metadata list not allowed");521 return NULL; 522 } 523 524 psListSetIterator( mdList, which);525 entry = psListGetCurrent( mdList);526 while (entry != NULL) {527 if (!strncmp( match, entry->name, strlen( match ))) {517 if (mdList == NULL) { 518 psError(__func__, "Null metadata list not allowed"); 519 return NULL; 520 } 521 522 mdList = md->list; 523 if (mdList == NULL) { 524 psError(__func__, "Null metadata list not allowed"); 525 return NULL; 526 } 527 528 psListSetIterator(mdList, which); 529 entry = psListGetCurrent(mdList); 530 while (entry != NULL) { 531 if (!strncmp(match, entry->name, strlen(match))) { 528 532 529 533 // Match found 530 534 return entry; 531 535 } 532 entry = psListGetPrevious( mdList);536 entry = psListGetPrevious(mdList); 533 537 } 534 538 535 539 // Match not found 536 if (entry == NULL) {537 psError( __func__, "Couldn't find metadata item with given match. Match: %s", match);540 if (entry == NULL) { 541 psError(__func__, "Couldn't find metadata item with given match. Match: %s", match); 538 542 } 539 543 … … 541 545 } 542 546 543 void psMetadataItemPrint( FILE *fd, const char *format, const psMetadataItem *restrict metadataItem)547 void psMetadataItemPrint(FILE * fd, const char *format, const psMetadataItem * restrict metadataItem) 544 548 { 545 549 psMetadataType type; 546 550 547 if (fd == NULL) {548 psError( __func__, "Null file descriptor not allowed");549 return ;550 } 551 552 if (format == NULL) {553 psError( __func__, "Null format not allowed");554 return ;555 } 556 557 if (metadataItem == NULL) {558 psError( __func__, "Null metadata not allowed");559 return ;551 if (fd == NULL) { 552 psError(__func__, "Null file descriptor not allowed"); 553 return; 554 } 555 556 if (format == NULL) { 557 psError(__func__, "Null format not allowed"); 558 return; 559 } 560 561 if (metadataItem == NULL) { 562 psError(__func__, "Null metadata not allowed"); 563 return; 560 564 } 561 565 562 566 type = metadataItem->type; 563 567 564 switch (type) {568 switch (type) { 565 569 case PS_META_BOOL: 566 fprintf( fd, format, metadataItem->data.B);570 fprintf(fd, format, metadataItem->data.B); 567 571 break; 568 572 case PS_META_S32: 569 fprintf( fd, format, metadataItem->data.S32);573 fprintf(fd, format, metadataItem->data.S32); 570 574 break; 571 575 case PS_META_F32: 572 fprintf( fd, format, metadataItem->data.F32);576 fprintf(fd, format, metadataItem->data.F32); 573 577 break; 574 578 case PS_META_F64: 575 fprintf( fd, format, metadataItem->data.F64);579 fprintf(fd, format, metadataItem->data.F64); 576 580 break; 577 581 case PS_META_STR: 578 fprintf( fd, format, metadataItem->data.V);582 fprintf(fd, format, metadataItem->data.V); 579 583 break; 580 584 case PS_META_ITEM_SET: … … 585 589 case PS_META_UNKNOWN: 586 590 default: 587 psError( __func__, " Invalid psMetadataType to print: %d", type);588 } 589 } 590 591 psMetadata *psMetadataFReadHeader( psMetadata *output, char *extName, int extNum, fitsfile *fd)591 psError(__func__, " Invalid psMetadataType to print: %d", type); 592 } 593 } 594 595 psMetadata *psMetadataFReadHeader(psMetadata * output, char *extName, int extNum, fitsfile * fd) 592 596 { 593 597 bool tempBool; 594 598 bool success; 595 599 char keyType; 596 char keyName[ FITS_LINE_SIZE];597 char keyValue[ FITS_LINE_SIZE];598 char keyComment[ FITS_LINE_SIZE];599 char fitsErr[ MAX_STRING_LENGTH];600 char keyName[FITS_LINE_SIZE]; 601 char keyValue[FITS_LINE_SIZE]; 602 char keyComment[FITS_LINE_SIZE]; 603 char fitsErr[MAX_STRING_LENGTH]; 600 604 int i; 601 605 int hduType = 0; … … 605 609 psMetadataType metadataItemType; 606 610 607 if(fd == NULL) { 608 psError( __func__, "Null FITS file descriptor not allowed" ); 609 return NULL; 610 } 611 612 if(extName == NULL && extNum == 0) { 613 psError( __func__, "Null extName and extNum = 0 not allowed" ); 614 return NULL; 615 } else 616 if(extName && extNum) { 617 psError( __func__, "Both extName and extNum arguments should not have non zero values." ); 618 return NULL; 619 } 620 611 if (fd == NULL) { 612 psError(__func__, "Null FITS file descriptor not allowed"); 613 return NULL; 614 } 615 616 if (extName == NULL && extNum == 0) { 617 psError(__func__, "Null extName and extNum = 0 not allowed"); 618 return NULL; 619 } else if (extName && extNum) { 620 psError(__func__, "Both extName and extNum arguments should not have non zero values."); 621 return NULL; 622 } 621 623 // Allocate metadata if user didn't 622 if (output == NULL) {624 if (output == NULL) { 623 625 output = psMetadataAlloc(); 624 626 } 625 626 627 // Move to user designated HDU number or HDU name in FITS file. HDU numbers starts at one. 627 if (extName != NULL) {628 if (fits_movnam_hdu( fd, ANY_HDU, extName, 0, &status) != 0) {628 if (extName != NULL) { 629 if (fits_movnam_hdu(fd, ANY_HDU, extName, 0, &status) != 0) { 629 630 FITS_ERROR("FITS error while locating header %s: %s", extName); 630 631 } 631 632 } else { 632 if (fits_movabs_hdu( fd, extNum, &hduType, &status) != 0) {633 if (fits_movabs_hdu(fd, extNum, &hduType, &status) != 0) { 633 634 FITS_ERROR("FITS error while locating header %d: %s", extNum); 634 635 } … … 636 637 637 638 // Get number of key names 638 if (fits_get_hdrpos( fd, &numKeys, &keyNum, &status) != 0) {639 if (fits_get_hdrpos(fd, &numKeys, &keyNum, &status) != 0) { 639 640 FITS_ERROR("FITS error while reading key %d: %s", keyNum); 640 641 } 641 642 642 // Get each key name. Keywords start at one. 643 for (i = 1; i <= numKeys; i++) {644 if (fits_read_keyn( fd, i, keyName, keyValue, keyComment, &status) != 0) {643 for (i = 1; i <= numKeys; i++) { 644 if (fits_read_keyn(fd, i, keyName, keyValue, keyComment, &status) != 0) { 645 645 FITS_ERROR("FITS error while reading key %d: %s", keyNum); 646 646 } 647 if (fits_get_keytype( keyValue, &keyType, &status) != 0) {648 fits_get_errstatus( status, fitsErr);649 if (status != VALUE_UNDEFINED) {647 if (fits_get_keytype(keyValue, &keyType, &status) != 0) { 648 fits_get_errstatus(status, fitsErr); 649 if (status != VALUE_UNDEFINED) { 650 650 FITS_ERROR("FITS error while determining key %d type: %s", keyNum); 651 651 } else { 652 // Some keywords are still valid even though they don't have a type, like COMMENTS and HISTORY 652 // Some keywords are still valid even though they don't have a type, like COMMENTS and 653 // HISTORY 653 654 keyType = 'C'; 654 655 status = 0; … … 656 657 } 657 658 658 switch (keyType) {659 switch (keyType) { 659 660 case 'I': 660 661 metadataItemType = PS_META_S32; 661 success = psMetadataAdd( output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, atoi( keyValue ) ); 662 success = 663 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, 664 atoi(keyValue)); 662 665 break; 663 666 case 'F': 664 667 metadataItemType = PS_META_F64; 665 success = psMetadataAdd( output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, atof( keyValue ) ); 668 success = 669 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, 670 atof(keyValue)); 666 671 break; 667 672 case 'C': 668 673 metadataItemType = PS_META_STR; 669 success = psMetadataAdd( output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, keyValue ); 674 success = 675 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, keyValue); 670 676 break; 671 677 case 'L': 672 678 metadataItemType = PS_META_BOOL; 673 tempBool = ( keyValue[ 0 ] == 'T' ) ? 1 : 0; 674 success = psMetadataAdd( output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, tempBool ); 679 tempBool = (keyValue[0] == 'T') ? 1 : 0; 680 success = 681 psMetadataAdd(output, PS_LIST_TAIL, keyName, metadataItemType, keyComment, tempBool); 675 682 break; 676 683 case 'U': 677 684 case 'X': 678 685 default: 679 psError( __func__, "Invalid psMetadataType: %c", keyType);686 psError(__func__, "Invalid psMetadataType: %c", keyType); 680 687 return output; 681 688 } 682 689 683 if (!success) {684 psError( __func__, "Failed to add metadata item. Name: %s", keyName);690 if (!success) { 691 psError(__func__, "Failed to add metadata item. Name: %s", keyName); 685 692 return output; 686 693 } -
trunk/psLib/src/collections/psMetadata.h
r1394 r1407 1 1 2 /** @file psMetadata.h 2 3 * … … 10 11 * @author Ross Harman, MHPCC 11 12 * 12 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08-0 5 20:55:22$13 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-08-07 00:06:06 $ 14 15 * 15 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 16 17 */ 17 18 #ifndef PS_METADATA_H 18 # define PS_METADATA_H19 20 # include <stdarg.h>21 # include <stdio.h>22 # include <fitsio.h>23 24 # include "psHash.h"25 # include "psList.h"19 # define PS_METADATA_H 20 21 # include <stdarg.h> 22 # include <stdio.h> 23 # include <fitsio.h> 24 25 # include "psHash.h" 26 # include "psList.h" 26 27 27 28 /// @addtogroup Metadata … … 33 34 */ 34 35 typedef enum { 35 PS_META_ITEM_SET = 0, ///< Null. Metadata is in psMetadataItem.items36 PS_META_BOOL, ///< Boolean data.37 PS_META_S32, ///< Signed 32-bit integer data.38 PS_META_F32, ///< Single-precision float data.39 PS_META_F64, ///< Double-precision float data.40 PS_META_STR, ///< String data (Stored in as void *).41 PS_META_IMG, ///< Image data (Stored in as void *).42 PS_META_JPEG, ///< JPEG data (Stored in as void .43 PS_META_PNG, ///< PNG data (Stored in as void *).44 PS_META_ASTROM, ///< Astrometric coefficients (Stored in as void *).45 PS_META_UNKNOWN, ///< Other data (Stored in as void *).46 PS_META_NTYPE ///< Number of types. Must be last.36 PS_META_ITEM_SET = 0, // /< Null. Metadata is in psMetadataItem.items 37 PS_META_BOOL, // /< Boolean data. 38 PS_META_S32, // /< Signed 32-bit integer data. 39 PS_META_F32, // /< Single-precision float data. 40 PS_META_F64, // /< Double-precision float data. 41 PS_META_STR, // /< String data (Stored in as void *). 42 PS_META_IMG, // /< Image data (Stored in as void *). 43 PS_META_JPEG, // /< JPEG data (Stored in as void . 44 PS_META_PNG, // /< PNG data (Stored in as void *). 45 PS_META_ASTROM, // /< Astrometric coefficients (Stored in as void *). 46 PS_META_UNKNOWN, // /< Other data (Stored in as void *). 47 PS_META_NTYPE // /< Number of types. Must be last. 47 48 } psMetadataType; 48 49 … … 54 55 typedef struct psMetadataItem 55 56 { 56 const int id; ///< Unique ID for metadata item. 57 char *restrict name; ///< Name of metadata item. 58 psMetadataType type; ///< Type of metadata item. 59 union 60 { 57 const int id; // /< Unique ID for metadata item. 58 char *restrict name; // /< Name of metadata item. 59 psMetadataType type; // /< Type of metadata item. 60 union { 61 61 bool B; 62 psS32 S32; ///< Signed 32-bit integer data.63 psF32 F32; ///< Single-precision float data.64 psF64 F64; ///< Double-precision float data.65 psPTR V; ///< Pointer to other type of data.66 } data; ///< Union for data types.67 char *comment; ///< Optional comment ("", not NULL).68 psList *restrict items; ///< List of psMetadataItems with same name.62 psS32 S32; // /< Signed 32-bit integer data. 63 psF32 F32; // /< Single-precision float data. 64 psF64 F64; // /< Double-precision float data. 65 psPTR V; // /< Pointer to other type of data. 66 } data; // /< Union for data types. 67 char *comment; // /< Optional comment ("", not NULL). 68 psList *restrict items; // /< List of psMetadataItems with same name. 69 69 } 70 70 psMetadataItem; … … 78 78 typedef struct psMetadata 79 79 { 80 psList *restrict list;81 psHash *restrict table;80 psList *restrict list; 81 psHash *restrict table; 82 82 } 83 83 psMetadata; 84 84 85 86 85 /*****************************************************************************/ 86 87 87 /* FUNCTION PROTOTYPES */ 88 88 89 /*****************************************************************************/ 89 90 … … 101 102 * @return psMetadataItem*: Pointer metadata item. 102 103 */ 103 psMetadataItem *psMetadataItemAlloc( 104 const char *name, ///< Name of metadata item. 105 psMetadataType type, ///< Type of metadata item. 106 const char *comment, ///< Comment for metadata item. 107 ... ///< Arguments for name formatting and metadata item data. 108 ); 104 psMetadataItem *psMetadataItemAlloc(const char *name, // /< Name of metadata item. 105 psMetadataType type, // /< Type of metadata item. 106 const char *comment, // /< Comment for metadata item. 107 ... // /< Arguments for name formatting and metadata item data. 108 ); 109 109 110 110 /** Create a metadata item with va_list. … … 121 121 * @return psMetadataItem*: Pointer metadata item. 122 122 */ 123 psMetadataItem *psMetadataItemAllocV( 124 const char *name, ///< Name of metadata item.125 psMetadataType type, ///< Type ofmetadata item.126 const char *comment, ///< Comment for metadata item.127 va_list list ///< Arguments for name formatting and metadata itemdata.128 );123 psMetadataItem *psMetadataItemAllocV(const char *name, // /< Name of metadata item. 124 psMetadataType type, // /< Type of metadata item. 125 const char *comment, // /< Comment for metadata item. 126 va_list list // /< Arguments for name formatting and metadata item 127 // data. 128 ); 129 129 130 130 /** Create a metadata collection. … … 134 134 * @return psMetadata*: Pointer metadata. 135 135 */ 136 psMetadata *psMetadataAlloc( 137 void ///< Void. 138 ); 136 psMetadata *psMetadataAlloc(void // /< Void. 137 ); 139 138 140 139 /** Add existing metadata item to metadata collection. … … 144 143 * @return bool: True for success, false for failure. 145 144 */ 146 bool psMetadataAddItem( 147 psMetadata *restrict md, ///< Metadata collection to insert metadat item. 148 int where, ///< Location to be added. 149 psMetadataItem *restrict item ///< Metadata item to be added. 150 ); 145 bool psMetadataAddItem(psMetadata * restrict md, // /< Metadata collection to insert metadat item. 146 int where, // /< Location to be added. 147 psMetadataItem * restrict item // /< Metadata item to be added. 148 ); 151 149 152 150 /** Create and add a metadata item to metadata collection. … … 156 154 * @return bool: True for success, false for failure. 157 155 */ 158 bool psMetadataAdd( 159 psMetadata *restrict md, ///< Metadata collection to insert metadat item. 160 int where, ///< Location to be added. 161 const char *name, ///< Name of metadata item. 162 psMetadataType type, ///< Type of metadata item. 163 const char *comment, ///< Comment for metadata item. 164 ... ///< Arguments for name formatting and metadata item data. 165 ); 156 bool psMetadataAdd(psMetadata * restrict md, // /< Metadata collection to insert metadat item. 157 int where, // /< Location to be added. 158 const char *name, // /< Name of metadata item. 159 psMetadataType type, // /< Type of metadata item. 160 const char *comment, // /< Comment for metadata item. 161 ... // /< Arguments for name formatting and metadata item data. 162 ); 166 163 167 164 /** Remove an item from metadata collection. … … 174 171 * @return bool: True for success, false for failure. 175 172 */ 176 bool psMetadataRemove( 177 psMetadata *restrict md, ///< Metadata collection to insert metadat item. 178 int where, ///< Location to be removed. 179 const char *restrict key ///< Name of metadata key. 180 ); 173 bool psMetadataRemove(psMetadata * restrict md, // /< Metadata collection to insert metadat item. 174 int where, // /< Location to be removed. 175 const char *restrict key // /< Name of metadata key. 176 ); 181 177 182 178 /** Find an item in the metadata collection based on key name. … … 187 183 * @return psMetadataItem*: Pointer metadata item. 188 184 */ 189 psMetadataItem *psMetadataLookup( 190 psMetadata *restrict md, ///< Metadata collection to insert metadatitem.191 const char *restrict key ///< Name of metadata key.192 );185 psMetadataItem *psMetadataLookup(psMetadata * restrict md, // /< Metadata collection to insert metadat 186 // item. 187 const char *restrict key // /< Name of metadata key. 188 ); 193 189 194 190 /** Find an item in the metadata collection based on list index. … … 198 194 * @return psMetadataItem*: Pointer metadata item. 199 195 */ 200 psMetadataItem *psMetadataGet( 201 psMetadata *restrict md, ///< Metadata collection to insert metadat item. 202 int where ///< Location to be retrieved. 203 ); 196 psMetadataItem *psMetadataGet(psMetadata * restrict md, // /< Metadata collection to insert metadat item. 197 int where // /< Location to be retrieved. 198 ); 204 199 205 200 /** Set or reset metadata iterator. … … 209 204 * @return void: void. 210 205 */ 211 bool psMetadataSetIterator( 212 psMetadata *restrict md, ///< Metadata collection to iterate. 213 int where ///< Location of iterator. 214 ); 206 bool psMetadataSetIterator(psMetadata * restrict md, // /< Metadata collection to iterate. 207 int where // /< Location of iterator. 208 ); 215 209 216 210 /** Get next metadata item. … … 220 214 * @return psMetadataItem*: Pointer metadata item. 221 215 */ 222 psMetadataItem *psMetadataGetNext( 223 psMetadata *restrict md, ///< Metadata collection to iterate. 224 const char *restrict match, ///< Beginning of key name. 225 int which ///< Iterator to be used. 226 ); 216 psMetadataItem *psMetadataGetNext(psMetadata * restrict md, // /< Metadata collection to iterate. 217 const char *restrict match, // /< Beginning of key name. 218 int which // /< Iterator to be used. 219 ); 227 220 228 221 /** Get previous metadata item. … … 232 225 * @return psMetadataItem*: Pointer metadata item. 233 226 */ 234 psMetadataItem *psMetadataGetPrevious( 235 psMetadata *restrict md, ///< Metadata collection to iterate. 236 const char *restrict match, ///< Beginning of key name. 237 int which ///< Iterator to be used. 238 ); 227 psMetadataItem *psMetadataGetPrevious(psMetadata * restrict md, // /< Metadata collection to iterate. 228 const char *restrict match, // /< Beginning of key name. 229 int which // /< Iterator to be used. 230 ); 239 231 240 232 /** Print metadata item to file. … … 248 240 * @return psMetadataItem*: Pointer metadata item. 249 241 */ 250 void psMetadataItemPrint( 251 FILE *fd, ///< Pointer to file to write metadata item. 252 const char *format, ///< Format to print metadata item. 253 const psMetadataItem *restrict metadataItem ///< Metadata item to print. 254 ); 242 void psMetadataItemPrint(FILE * fd, // /< Pointer to file to write metadata item. 243 const char *format, // /< Format to print metadata item. 244 const psMetadataItem * restrict metadataItem // /< Metadata item to print. 245 ); 255 246 256 247 /** Read metadata header. … … 261 252 * @return psMetadata*: Pointer metadata. 262 253 */ 263 psMetadata *psMetadataReadHeader( 264 psMetadata *output, ///< Resulting metadata from read. 265 char *extname, ///< File name extension string. 266 int extnum, ///< File name extension number. Starts at 1. 267 char *filename ///< Name of file to read. 268 ); 254 psMetadata *psMetadataReadHeader(psMetadata * output, // /< Resulting metadata from read. 255 char *extname, // /< File name extension string. 256 int extnum, // /< File name extension number. Starts at 1. 257 char *filename // /< Name of file to read. 258 ); 269 259 270 260 /** Read metadata header. … … 274 264 * @return psMetadata*: Pointer metadata. 275 265 */ 276 psMetadata *psMetadataFReadHeader( 277 psMetadata *output, ///< Resulting metadata from read.278 char *extName, ///< File name extension string.279 int extNum, ///< File name extension number.280 fitsfile *fd ///< Pointer to file to read.281 ); 266 psMetadata *psMetadataFReadHeader(psMetadata * output, // /< Resulting metadata from read. 267 char *extName, // /< File name extension string. 268 int extNum, // /< File name extension number. 269 fitsfile * fd // /< Pointer to file to read. 270 ); 271 282 272 /// @} 283 273 -
trunk/psLib/src/collections/psScalar.c
r1406 r1407 1 1 2 /** @file psScalar.c 2 3 * … … 8 9 * @author Ross Harman, MHPCC 9 10 * 10 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-08-0 6 22:34:05$11 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-08-07 00:06:06 $ 12 13 * 13 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 16 16 17 /******************************************************************************/ 18 17 19 /* INCLUDE FILES */ 20 18 21 /******************************************************************************/ 19 22 #include "psMemory.h" … … 24 27 25 28 /******************************************************************************/ 29 26 30 /* DEFINE STATEMENTS */ 31 27 32 /******************************************************************************/ 28 33 … … 30 35 31 36 /******************************************************************************/ 37 32 38 /* TYPE DEFINITIONS */ 39 33 40 /******************************************************************************/ 34 41 … … 36 43 37 44 /*****************************************************************************/ 45 38 46 /* GLOBAL VARIABLES */ 47 39 48 /*****************************************************************************/ 40 49 … … 42 51 43 52 /*****************************************************************************/ 53 44 54 /* FILE STATIC VARIABLES */ 55 45 56 /*****************************************************************************/ 46 57 … … 48 59 49 60 /*****************************************************************************/ 61 50 62 /* FUNCTION IMPLEMENTATION - LOCAL */ 63 51 64 /*****************************************************************************/ 52 65 … … 54 67 55 68 /*****************************************************************************/ 69 56 70 /* FUNCTION IMPLEMENTATION - PUBLIC */ 71 57 72 /*****************************************************************************/ 58 73 psScalar *psScalarAlloc(psC64 value, psElemType dataType) … … 61 76 62 77 // Create scalar 63 scalar = (psScalar *) psAlloc(sizeof(psScalar));64 if (scalar == NULL) {65 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);78 scalar = (psScalar *) psAlloc(sizeof(psScalar)); 79 if (scalar == NULL) { 80 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); 66 81 } 67 82 … … 71 86 switch (dataType) { 72 87 case PS_TYPE_S8: 73 scalar->data.S8 = (psS8) value;88 scalar->data.S8 = (psS8) value; 74 89 break; 75 90 case PS_TYPE_U8: 76 scalar->data.U8 = (psU8) value;91 scalar->data.U8 = (psU8) value; 77 92 break; 78 93 case PS_TYPE_S16: 79 scalar->data.S16 = (psS16) value;94 scalar->data.S16 = (psS16) value; 80 95 break; 81 96 case PS_TYPE_U16: 82 scalar->data.U16 = (psU16) value;97 scalar->data.U16 = (psU16) value; 83 98 break; 84 99 case PS_TYPE_S32: 85 scalar->data.S32 = (psS32) value;100 scalar->data.S32 = (psS32) value; 86 101 break; 87 102 case PS_TYPE_U32: 88 scalar->data.U32 = (psU32) value;103 scalar->data.U32 = (psU32) value; 89 104 break; 90 105 case PS_TYPE_S64: 91 scalar->data.S64 = (psS64) value;106 scalar->data.S64 = (psS64) value; 92 107 break; 93 108 case PS_TYPE_U64: 94 scalar->data.U64 = (psU64) value;109 scalar->data.U64 = (psU64) value; 95 110 break; 96 111 case PS_TYPE_F32: 97 scalar->data.F32 = (psF32) value;112 scalar->data.F32 = (psF32) value; 98 113 break; 99 114 case PS_TYPE_F64: 100 scalar->data.F64 = (psF64) value;115 scalar->data.F64 = (psF64) value; 101 116 break; 102 117 case PS_TYPE_C32: 103 scalar->data.C32 = (psC32) value;118 scalar->data.C32 = (psC32) value; 104 119 break; 105 120 case PS_TYPE_C64: 106 scalar->data.C64 = (psC64) value;121 scalar->data.C64 = (psC64) value; 107 122 break; 108 123 default: … … 110 125 } 111 126 112 113 127 return scalar; 114 128 } 115 129 116 void psScalarFree(psScalar * restrict scalar)130 void psScalarFree(psScalar * restrict scalar) 117 131 { 118 132 if (scalar == NULL) { … … 122 136 psFree(scalar); 123 137 } 124 125 -
trunk/psLib/src/collections/psScalar.h
r1406 r1407 1 1 2 /** @file psScalar.h 2 3 * … … 10 11 * @author Ross Harman, MHPCC 11 12 * 12 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08-0 6 22:34:05$13 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-08-07 00:06:06 $ 14 15 * 15 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 17 18 18 19 #ifndef PS_SCALAR_H 19 # define PS_SCALAR_H20 # define PS_SCALAR_H 20 21 21 # include "psType.h"22 # include "psType.h" 22 23 23 24 /// @addtogroup Scalar … … 31 32 typedef struct 32 33 { 33 psType type; ///< Type of data.34 psType type; // /< Type of data. 34 35 35 36 union { 36 psU8 U8; ///< Unsigned 8-bit integer data.37 psU16 U16; ///< Unsigned 16-bit integer data.38 psU32 U32; ///< Unsigned 32-bit integer data.39 psU64 U64; ///< Unsigned 64-bit integer data.40 psS8 S8; ///< Signed 8-bit integer data.41 psS16 S16; ///< Signed 16-bit integer data.42 psS32 S32; ///< Signed 32-bit integer data.43 psS64 S64; ///< Signed 64-bit integer data.44 psF32 F32; ///< Single-precision float data.45 psF64 F64; ///< Double-precision float data.46 psC32 C32; ///< Single-precision complex data.47 psC64 C64; ///< Double-precision complex data.48 } data; ///< Union for data types.37 psU8 U8; // /< Unsigned 8-bit integer data. 38 psU16 U16; // /< Unsigned 16-bit integer data. 39 psU32 U32; // /< Unsigned 32-bit integer data. 40 psU64 U64; // /< Unsigned 64-bit integer data. 41 psS8 S8; // /< Signed 8-bit integer data. 42 psS16 S16; // /< Signed 16-bit integer data. 43 psS32 S32; // /< Signed 32-bit integer data. 44 psS64 S64; // /< Signed 64-bit integer data. 45 psF32 F32; // /< Single-precision float data. 46 psF64 F64; // /< Double-precision float data. 47 psC32 C32; // /< Single-precision complex data. 48 psC64 C64; // /< Double-precision complex data. 49 } data; // /< Union for data types. 49 50 } 50 51 psScalar; 51 52 52 53 /*****************************************************************************/ 54 53 55 /* FUNCTION PROTOTYPES */ 56 54 57 /*****************************************************************************/ 55 58 … … 62 65 * 63 66 */ 64 psScalar *psScalarAlloc( 65 psC64 value, ///< Data to be put into psScalar. 66 psElemType dataType ///< Type of data to be held by psScalar. 67 ); 68 67 psScalar *psScalarAlloc(psC64 value, // /< Data to be put into psScalar. 68 psElemType dataType // /< Type of data to be held by psScalar. 69 ); 69 70 70 71 /** Deallocate a scalar. … … 75 76 * 76 77 */ 77 void psScalarFree( 78 psScalar *restrict scalar ///< Scalar to free. 79 ); 78 void psScalarFree(psScalar * restrict scalar // /< Scalar to free. 79 ); 80 80 81 81 /// @} -
trunk/psLib/src/collections/psVector.c
r1406 r1407 1 1 2 /** @file psVector.c 2 3 * … … 8 9 * @author Ross Harman, MHPCC 9 10 * 10 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-08-0 6 22:34:05$11 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-08-07 00:06:06 $ 12 13 * 13 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 16 16 17 /******************************************************************************/ 18 17 19 /* INCLUDE FILES */ 18 /******************************************************************************/ 19 #include <string.h> // for memcpy 20 21 /******************************************************************************/ 22 #include <string.h> // for memcpy 20 23 #include <stdlib.h> 21 24 #include <math.h> … … 28 31 29 32 /******************************************************************************/ 33 30 34 /* DEFINE STATEMENTS */ 35 31 36 /******************************************************************************/ 32 37 … … 34 39 35 40 /******************************************************************************/ 41 36 42 /* TYPE DEFINITIONS */ 43 37 44 /******************************************************************************/ 38 45 … … 40 47 41 48 /*****************************************************************************/ 49 42 50 /* GLOBAL VARIABLES */ 51 43 52 /*****************************************************************************/ 44 53 … … 46 55 47 56 /*****************************************************************************/ 57 48 58 /* FILE STATIC VARIABLES */ 59 49 60 /*****************************************************************************/ 50 61 … … 52 63 53 64 /*****************************************************************************/ 65 54 66 /* FUNCTION IMPLEMENTATION - LOCAL */ 55 /*****************************************************************************/ 56 static void vectorFree( psVector *restrict psVec ); 57 58 /*****************************************************************************/ 67 68 /*****************************************************************************/ 69 static void vectorFree(psVector * restrict psVec); 70 71 /*****************************************************************************/ 72 59 73 /* FUNCTION IMPLEMENTATION - PUBLIC */ 60 /*****************************************************************************/ 61 psVector* psVectorAlloc( unsigned int nalloc, psElemType elemType ) 62 { 63 psVector * psVec = NULL; 74 75 /*****************************************************************************/ 76 psVector *psVectorAlloc(unsigned int nalloc, psElemType elemType) 77 { 78 psVector *psVec = NULL; 64 79 int elementSize = 0; 65 80 66 81 // Invalid nalloc 67 if ( nalloc < 1) {68 psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc);82 if (nalloc < 1) { 83 psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc); 69 84 return NULL; 70 85 } 71 86 72 elementSize = PSELEMTYPE_SIZEOF( elemType);87 elementSize = PSELEMTYPE_SIZEOF(elemType); 73 88 74 89 // Create vector struct 75 psVec = ( psVector * ) psAlloc( sizeof( psVector ));76 p_psMemSetDeallocator( psVec, ( psFreeFcn ) vectorFree);90 psVec = (psVector *) psAlloc(sizeof(psVector)); 91 p_psMemSetDeallocator(psVec, (psFreeFcn) vectorFree); 77 92 78 93 psVec->type.dimen = PS_DIMEN_VECTOR; … … 82 97 83 98 // Create vector data array 84 psVec->data.V = psAlloc( nalloc * elementSize);99 psVec->data.V = psAlloc(nalloc * elementSize); 85 100 86 101 return psVec; 87 102 } 88 103 89 psVector *psVectorRealloc( unsigned int nalloc, psVector *restrict in)104 psVector *psVectorRealloc(unsigned int nalloc, psVector * restrict in) 90 105 { 91 106 int elementSize = 0; … … 93 108 94 109 // Invalid nalloc 95 if ( nalloc < 1) {96 psError( __func__, "Invalid value for realloc (%d)\n", nalloc);110 if (nalloc < 1) { 111 psError(__func__, "Invalid value for realloc (%d)\n", nalloc); 97 112 return NULL; 98 113 } 99 114 100 if ( in == NULL) {101 psError( __func__, "Null input vector\n");115 if (in == NULL) { 116 psError(__func__, "Null input vector\n"); 102 117 return NULL; 103 } else 104 if ( in->nalloc != nalloc ) { // No need to realloc to same size 105 elemType = in->type.type; 106 elementSize = PSELEMTYPE_SIZEOF( elemType ); 107 if ( nalloc < in->n ) { 108 in->n = nalloc; 109 } 110 111 // Realloc after decrementation to avoid accessing freed array elements 112 in->data.V = psRealloc( in->data.V, nalloc * elementSize ); 113 in->nalloc = nalloc; 118 } else if (in->nalloc != nalloc) { // No need to realloc to same size 119 elemType = in->type.type; 120 elementSize = PSELEMTYPE_SIZEOF(elemType); 121 if (nalloc < in->n) { 122 in->n = nalloc; 114 123 } 124 // Realloc after decrementation to avoid accessing freed array elements 125 in->data.V = psRealloc(in->data.V, nalloc * elementSize); 126 in->nalloc = nalloc; 127 } 115 128 116 129 return in; 117 130 } 118 131 119 psVector *psVectorRecycle( psVector *restrict in, unsigned int nalloc, psElemType type)132 psVector *psVectorRecycle(psVector * restrict in, unsigned int nalloc, psElemType type) 120 133 { 121 134 psElemType elemType; 122 135 123 if ( in == NULL) {124 return psVectorAlloc( nalloc, type);136 if (in == NULL) { 137 return psVectorAlloc(nalloc, type); 125 138 } 126 139 127 140 elemType = in->type.type; 128 141 129 if ( in->nalloc == nalloc && elemType == type) {142 if (in->nalloc == nalloc && elemType == type) { 130 143 // it is proper size/type already 131 144 return in; 132 145 } 133 134 146 // Invalid nalloc 135 if ( nalloc < 1) {136 psError( __func__, "Invalid value for nalloc (%d)\n", nalloc);137 psFree( in);147 if (nalloc < 1) { 148 psError(__func__, "Invalid value for nalloc (%d)\n", nalloc); 149 psFree(in); 138 150 return NULL; 139 151 } 140 152 141 142 in->data.V = psRealloc( in->data.V, nalloc * PSELEMTYPE_SIZEOF( type ) ); 153 in->data.V = psRealloc(in->data.V, nalloc * PSELEMTYPE_SIZEOF(type)); 143 154 144 155 in->type.type = type; … … 149 160 } 150 161 151 psVector *psVectorSort( psVector *restrict outVector, const psVector *restrict inVector)162 psVector *psVectorSort(psVector * restrict outVector, const psVector * restrict inVector) 152 163 { 153 164 int inN = 0; … … 158 169 psElemType inType = 0; 159 170 160 if ( inVector == NULL) {161 psError( __func__, " : Line %d - Null input vector\n", __LINE__);171 if (inVector == NULL) { 172 psError(__func__, " : Line %d - Null input vector\n", __LINE__); 162 173 return outVector; 163 174 } … … 166 177 inN = inVector->n; 167 178 inVec = inVector->data.V; 168 elSize = PSELEMTYPE_SIZEOF( inType);169 170 if ( outVector == NULL) {171 outVector = psVectorAlloc( inN, inType);179 elSize = PSELEMTYPE_SIZEOF(inType); 180 181 if (outVector == NULL) { 182 outVector = psVectorAlloc(inN, inType); 172 183 outVector->n = inVector->n; 173 184 } … … 176 187 outVec = outVector->data.V; 177 188 178 if ( inN != outN ) { 179 psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__, 180 inN, outN ); 181 return outVector; 182 } 183 184 if ( inType != outVector->type.type ) { 185 psError( __func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__, 186 inType, outVector->type.type ); 187 return outVector; 188 } 189 190 if ( inN == 0 ) { 191 psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ ); 192 return outVector; 193 } 194 195 if ( outN == 0 ) { 196 psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ ); 197 return outVector; 198 } 199 189 if (inN != outN) { 190 psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", 191 __LINE__, inN, outN); 192 return outVector; 193 } 194 195 if (inType != outVector->type.type) { 196 psError(__func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__, 197 inType, outVector->type.type); 198 return outVector; 199 } 200 201 if (inN == 0) { 202 psError(__func__, " : Line %d - No elements in use for input vector\n", __LINE__); 203 return outVector; 204 } 205 206 if (outN == 0) { 207 psError(__func__, " : Line %d - No elements in use for output vector\n", __LINE__); 208 return outVector; 209 } 200 210 // Copy input vector values into output vector 201 memcpy( outVec, inVec, elSize * outN);211 memcpy(outVec, inVec, elSize * outN); 202 212 203 213 // Sort output vector 204 switch ( inType) {214 switch (inType) { 205 215 case PS_TYPE_U8: 206 qsort( outVec, inN, elSize, psCompareU8);216 qsort(outVec, inN, elSize, psCompareU8); 207 217 break; 208 218 case PS_TYPE_U16: 209 qsort( outVec, inN, elSize, psCompareU16);219 qsort(outVec, inN, elSize, psCompareU16); 210 220 break; 211 221 case PS_TYPE_U32: 212 qsort( outVec, inN, elSize, psCompareU32);222 qsort(outVec, inN, elSize, psCompareU32); 213 223 break; 214 224 case PS_TYPE_U64: 215 qsort( outVec, inN, elSize, psCompareU64);225 qsort(outVec, inN, elSize, psCompareU64); 216 226 break; 217 227 case PS_TYPE_S8: 218 qsort( outVec, inN, elSize, psCompareS8);228 qsort(outVec, inN, elSize, psCompareS8); 219 229 break; 220 230 case PS_TYPE_S16: 221 qsort( outVec, inN, elSize, psCompareS16);231 qsort(outVec, inN, elSize, psCompareS16); 222 232 break; 223 233 case PS_TYPE_S32: 224 qsort( outVec, inN, elSize, psCompareS32);234 qsort(outVec, inN, elSize, psCompareS32); 225 235 break; 226 236 case PS_TYPE_S64: 227 qsort( outVec, inN, elSize, psCompareS64);237 qsort(outVec, inN, elSize, psCompareS64); 228 238 break; 229 239 case PS_TYPE_F32: 230 qsort( outVec, inN, elSize, psCompareF32);240 qsort(outVec, inN, elSize, psCompareF32); 231 241 break; 232 242 case PS_TYPE_F64: 233 qsort( outVec, inN, elSize, psCompareF64);243 qsort(outVec, inN, elSize, psCompareF64); 234 244 break; 235 245 default: 236 psError( __func__, " : Line %d - Invalid psType\n", __LINE__);246 psError(__func__, " : Line %d - Invalid psType\n", __LINE__); 237 247 } 238 248 … … 251 261 } 252 262 253 psVector *psVectorSortIndex( psVector *restrict outVector, const psVector *restrict inVector)263 psVector *psVectorSortIndex(psVector * restrict outVector, const psVector * restrict inVector) 254 264 { 255 265 int inN = 0; … … 263 273 psElemType inType = 0; 264 274 265 if ( inVector == NULL) {266 psError( __func__, " : Line %d - Null input vector\n", __LINE__);275 if (inVector == NULL) { 276 psError(__func__, " : Line %d - Null input vector\n", __LINE__); 267 277 return outVector; 268 278 } … … 272 282 inType = inVector->type.type; 273 283 274 if ( outVector == NULL) {275 outVector = psVectorAlloc( inN, PS_TYPE_U32);284 if (outVector == NULL) { 285 outVector = psVectorAlloc(inN, PS_TYPE_U32); 276 286 outVector->n = inN; 277 287 } … … 280 290 outVec = outVector->data.V; 281 291 282 if ( inN != outN) {283 psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",284 __LINE__, inN, outN);285 return outVector; 286 } 287 288 if ( outVector->type.type != PS_TYPE_U32) {289 psError( __func__, " : Line %d - Output vector is not of type U32: out=%d\n",290 __LINE__, outVector->type.type);291 return outVector; 292 } 293 294 tmpVector = psVectorAlloc( inN, inType);292 if (inN != outN) { 293 psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", 294 __LINE__, inN, outN); 295 return outVector; 296 } 297 298 if (outVector->type.type != PS_TYPE_U32) { 299 psError(__func__, " : Line %d - Output vector is not of type U32: out=%d\n", 300 __LINE__, outVector->type.type); 301 return outVector; 302 } 303 304 tmpVector = psVectorAlloc(inN, inType); 295 305 tmpVector->n = inN; 296 tmpVector = psVectorSort( tmpVector, inVector);306 tmpVector = psVectorSort(tmpVector, inVector); 297 307 298 308 // Sort output vector 299 switch ( inType) {309 switch (inType) { 300 310 case PS_TYPE_U8: 301 SORT_INDICES( U8);311 SORT_INDICES(U8); 302 312 break; 303 313 case PS_TYPE_U16: 304 SORT_INDICES( U16);314 SORT_INDICES(U16); 305 315 break; 306 316 case PS_TYPE_U32: 307 SORT_INDICES( U32);317 SORT_INDICES(U32); 308 318 break; 309 319 case PS_TYPE_U64: 310 SORT_INDICES( U64);320 SORT_INDICES(U64); 311 321 break; 312 322 case PS_TYPE_S8: 313 SORT_INDICES( S8);323 SORT_INDICES(S8); 314 324 break; 315 325 case PS_TYPE_S16: 316 SORT_INDICES( S16);326 SORT_INDICES(S16); 317 327 break; 318 328 case PS_TYPE_S32: 319 SORT_INDICES( S32);329 SORT_INDICES(S32); 320 330 break; 321 331 case PS_TYPE_S64: 322 SORT_INDICES( S64);332 SORT_INDICES(S64); 323 333 break; 324 334 case PS_TYPE_F32: 325 SORT_INDICES( F32);335 SORT_INDICES(F32); 326 336 break; 327 337 case PS_TYPE_F64: 328 SORT_INDICES( F64);338 SORT_INDICES(F64); 329 339 break; 330 340 default: 331 psError( __func__, " : Line %d - Invalid psType\n", __LINE__);341 psError(__func__, " : Line %d - Invalid psType\n", __LINE__); 332 342 } 333 343 334 344 // Free temp memory 335 psFree( tmpVector);345 psFree(tmpVector); 336 346 337 347 return outVector; 338 348 } 339 349 340 static void vectorFree( psVector *restrict psVec)341 { 342 if ( psVec == NULL) {343 return ;344 } 345 346 psFree( psVec->data.V);347 } 350 static void vectorFree(psVector * restrict psVec) 351 { 352 if (psVec == NULL) { 353 return; 354 } 355 356 psFree(psVec->data.V); 357 } -
trunk/psLib/src/collections/psVector.h
r1406 r1407 1 1 2 /** @file psVector.h 2 3 * … … 11 12 * @author Ross Harman, MHPCC 12 13 * 13 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-08-0 6 22:34:05$14 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-08-07 00:06:06 $ 15 16 * 16 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 19 19 20 #ifndef PS_VECTOR_H 20 # define PS_VECTOR_H21 # define PS_VECTOR_H 21 22 22 # include "psType.h"23 # include "psType.h" 23 24 24 25 /// @addtogroup Vector … … 32 33 typedef struct 33 34 { 34 psType type; ///< Type of data.35 unsigned int nalloc; ///< Total number of elements available.36 unsigned int n; ///< Number of elements in use.35 psType type; // /< Type of data. 36 unsigned int nalloc; // /< Total number of elements available. 37 unsigned int n; // /< Number of elements in use. 37 38 38 39 union { 39 psU8 *U8; ///< Unsigned 8-bit integer data.40 psU16 *U16; ///< Unsigned 16-bit integer data.41 psU32 *U32; ///< Unsigned 32-bit integer data.42 psU64 *U64; ///< Unsigned 64-bit integer data.43 psS8 *S8; ///< Signed 8-bit integer data.44 psS16 *S16; ///< Signed 16-bit integer data.45 psS32 *S32; ///< Signed 32-bit integer data.46 psS64 *S64; ///< Signed 64-bit integer data.47 psF32 *F32; ///< Single-precision float data.48 psF64 *F64; ///< Double-precision float data.49 psC32 *C32; ///< Single-precision complex data.50 psC64 *C64; ///< Double-precision complex data.51 psPTR V; ///< Pointer to data.52 } data; ///< Union for data types.40 psU8 *U8; // /< Unsigned 8-bit integer data. 41 psU16 *U16; // /< Unsigned 16-bit integer data. 42 psU32 *U32; // /< Unsigned 32-bit integer data. 43 psU64 *U64; // /< Unsigned 64-bit integer data. 44 psS8 *S8; // /< Signed 8-bit integer data. 45 psS16 *S16; // /< Signed 16-bit integer data. 46 psS32 *S32; // /< Signed 32-bit integer data. 47 psS64 *S64; // /< Signed 64-bit integer data. 48 psF32 *F32; // /< Single-precision float data. 49 psF64 *F64; // /< Double-precision float data. 50 psC32 *C32; // /< Single-precision complex data. 51 psC64 *C64; // /< Double-precision complex data. 52 psPTR V; // /< Pointer to data. 53 } data; // /< Union for data types. 53 54 } 54 55 psVector; 55 56 56 57 /*****************************************************************************/ 58 57 59 /* FUNCTION PROTOTYPES */ 60 58 61 /*****************************************************************************/ 59 62 … … 65 68 * 66 69 */ 67 psVector *psVectorAlloc( 68 unsigned int nalloc, ///< Total number of elements to make available. 69 psElemType dataType ///< Type of data to be held by vector. 70 ); 70 psVector *psVectorAlloc(unsigned int nalloc, // /< Total number of elements to make available. 71 psElemType dataType // /< Type of data to be held by vector. 72 ); 71 73 72 74 /** Reallocate a vector. … … 78 80 * 79 81 */ 80 psVector *psVectorRealloc( 81 unsigned int nalloc, ///< Total number of elements to make available. 82 psVector *restrict psVec ///< Vector to reallocate. 83 ); 82 psVector *psVectorRealloc(unsigned int nalloc, // /< Total number of elements to make available. 83 psVector * restrict psVec // /< Vector to reallocate. 84 ); 84 85 85 86 /** Recycle a vector. … … 91 92 * 92 93 */ 93 psVector *psVectorRecycle( 94 psVector *restrict psVec, 95 ///< Vector to recycle. If NULL, a new vector is created. No effort taken to preserve the values. 96 97 unsigned int nalloc, ///< Total number of elements to make available. 98 psElemType type ///< the datatype of the returned vector 99 ); 94 psVector *psVectorRecycle(psVector * restrict psVec, 95 // /< Vector to recycle. If NULL, a new vector is created. No effort taken to 96 // preserve the values. 97 unsigned int nalloc, // /< Total number of elements to make available. 98 psElemType type // /< the datatype of the returned vector 99 ); 100 100 101 101 /** Sort an array of floats. … … 107 107 */ 108 108 109 psVector *psVectorSort( 110 psVector *restrict outVector, ///< the output vector to recycle, or NULL if newvector desired.111 const psVector *restrict inVector ///< the vector to sort.112 );109 psVector *psVectorSort(psVector * restrict outVector, // /< the output vector to recycle, or NULL if new 110 // vector desired. 111 const psVector * restrict inVector // /< the vector to sort. 112 ); 113 113 114 114 /** Creates an array of indices based on sort odred of float array. … … 120 120 */ 121 121 122 psVector *psVectorSortIndex( 123 psVector *restrict outVector, 124 const psVector *restrict inVector 125 ); 126 122 psVector *psVectorSortIndex(psVector * restrict outVector, const psVector * restrict inVector); 127 123 128 124 /// @}
Note:
See TracChangeset
for help on using the changeset viewer.
