Changeset 486
- Timestamp:
- Apr 20, 2004, 2:40:32 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 5 edited
-
collections/psArray.c (modified) (8 diffs)
-
collections/psArray.h (modified) (6 diffs)
-
collections/psSort.c (modified) (2 diffs)
-
types/psArray.c (modified) (8 diffs)
-
types/psArray.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psArray.c
r485 r486 8 8 * @author Ross Harman, MHPCC 9 9 * 10 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-04-21 00: 18:05$10 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-04-21 00:40:32 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 #include "psMemory.h" 20 20 #include "psArray.h" 21 #include "psLogMsg.h"22 21 23 22 /******************************************************************************/ … … 54 53 /* FUNCTION IMPLEMENTATION - PUBLIC */ 55 54 /*****************************************************************************/ 55 56 psIntArray* psIntArrayAlloc(int nalloc) 57 { 58 psIntArray *psArr = (psIntArray*)p_psAlloc(sizeof(psIntArray), __FILE__, __LINE__); 59 psArr->type.dimen = PS_DIMEN_VECTOR; 60 psArr->type.type = PS_TYPE_INT; 61 psArr->nalloc = nalloc; 62 psArr->n = 0; 63 64 if(nalloc == 0) { 65 psArr->arr = NULL; 66 } else { 67 psArr->arr = p_psAlloc(nalloc*sizeof(int), __FILE__, __LINE__); 68 } 69 70 return psArr; 71 } 72 73 psIntArray *psIntArrayRealloc(psIntArray *psArr, int nalloc) 74 { 75 if(psArr == NULL) { 76 return psIntArrayAlloc(nalloc); 77 } 78 if(nalloc <= psArr->nalloc) { 79 if (psArr->n < nalloc) { 80 psArr->n = nalloc; 81 } 82 } else { 83 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof(int), __FILE__, __LINE__); 84 psArr->nalloc = nalloc; 85 } 86 return psArr; 87 } 88 89 void psIntArrayFree(psIntArray *restrict psArr) 90 { 91 if (psArr == NULL) { 92 return; 93 } 94 p_psFree(psArr->arr, __FILE__, __LINE__); 95 p_psFree(psArr, __FILE__, __LINE__); 96 } 56 97 57 98 psFloatArray* psFloatArrayAlloc(int nalloc) … … 97 138 } 98 139 99 ps IntArray* psIntArrayAlloc(int nalloc)140 psDoubleArray* psDoubleArrayAlloc(int nalloc) 100 141 { 101 ps IntArray *psArr = (psIntArray*)p_psAlloc(sizeof(psIntArray), __FILE__, __LINE__);142 psDoubleArray *psArr = (psDoubleArray*)p_psAlloc(sizeof(psDoubleArray), __FILE__, __LINE__); 102 143 psArr->type.dimen = PS_DIMEN_VECTOR; 103 psArr->type.type = PS_TYPE_ INT;144 psArr->type.type = PS_TYPE_DOUBLE; 104 145 psArr->nalloc = nalloc; 105 146 psArr->n = 0; … … 108 149 psArr->arr = NULL; 109 150 } else { 110 psArr->arr = p_psAlloc(nalloc*sizeof( int), __FILE__, __LINE__);151 psArr->arr = p_psAlloc(nalloc*sizeof(double), __FILE__, __LINE__); 111 152 } 112 153 … … 114 155 } 115 156 116 ps IntArray *psIntArrayRealloc(psIntArray *psArr, int nalloc)157 psDoubleArray *psDoubleArrayRealloc(psDoubleArray *psArr, int nalloc) 117 158 { 118 159 if(psArr == NULL) { 119 return ps IntArrayAlloc(nalloc);160 return psDoubleArrayAlloc(nalloc); 120 161 } 121 162 if(nalloc <= psArr->nalloc) { … … 124 165 } 125 166 } else { 126 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof( int), __FILE__, __LINE__);167 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof(double), __FILE__, __LINE__); 127 168 psArr->nalloc = nalloc; 128 169 } … … 130 171 } 131 172 132 void ps IntArrayFree(psIntArray *restrict psArr)173 void psDoubleArrayFree(psDoubleArray *restrict psArr) 133 174 { 134 175 if (psArr == NULL) { -
trunk/psLib/src/collections/psArray.h
r485 r486 8 8 * @author Ross Harman, MHPCC 9 9 * 10 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-04-21 00: 18:05$10 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-04-21 00:40:32 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 96 96 typedef struct 97 97 { 98 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!99 int nalloc; ///< Total number of elements available.100 int n; ///< Number of elements in use.101 float *arr; ///< Array data.98 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 99 int nalloc; ///< Total number of elements available. 100 int n; ///< Number of elements in use. 101 float *arr; ///< Array data. 102 102 } 103 103 psFloatArray; 104 105 /** An array of doubles. 106 * 107 * Struct for maintaining an array of double precision floating point numbers. 108 * 109 */ 110 typedef struct 111 { 112 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 113 int nalloc; ///< Total number of elements available. 114 int n; ///< Number of elements in use. 115 double *arr; ///< Array data. 116 } 117 psDoubleArray; 104 118 105 119 /*****************************************************************************/ … … 107 121 /*****************************************************************************/ 108 122 109 /** Allocate an integer array */ 123 /** Allocate an integer array. 124 * 125 * Uses psLib memory allocation functions to create an array of integers as defined by the psIntArray struct. 126 * 127 */ 110 128 psIntArray *psIntArrayAlloc( 111 129 int nalloc ///< Total number of elements to make available 112 130 ); 113 131 114 /** Reallocate an integer array */ 132 /** Reallocate an integer array. 133 * 134 * Uses psLib memory allocation functions to reallocate an array of integers as defined by the psIntArray 135 * struct. 136 * 137 */ 115 138 psIntArray *psIntArrayRealloc( 116 139 psIntArray *myArray, ///< Array to reallocate. … … 119 142 120 143 121 /** Deallocate an integer array */ 144 /** Deallocate an integer array 145 * 146 * Uses psLib memory allocation functions to deallocate an array of integers as defined by the psIntArray 147 * struct. 148 * 149 */ 122 150 void psIntArrayFree( 123 151 psIntArray *restrict myArray ///< Array to free … … 153 181 psFloatArray *restrict myArray ///< Array to free 154 182 ); 183 184 /** Allocate a Double array. 185 * 186 * Uses psLib memory allocation functions to create an array of doubles as defined by the psDoubleArray 187 * struct. 188 * 189 */ 190 psDoubleArray *psDoubleArrayAlloc( 191 int nalloc ///< Total number of elements to make available. 192 ); 193 194 /** Reallocate a Double array. 195 * 196 * Uses psLib memory allocation functions to reallocate an array of Doubles as defined by the psDoubleArray 197 * struct. 198 * 199 */ 200 psDoubleArray *psDoubleArrayRealloc( 201 psDoubleArray *myArray, ///< Array to reallocate. 202 int nalloc ///< Total number of elements to make available. 203 ); 204 205 /** Deallocate a Double array 206 * 207 * Uses psLib memory allocation functions to deallocate an array of doubles as defined by the psDoubleArray 208 * struct. 209 * 210 */ 211 void psDoubleArrayFree( 212 psDoubleArray *restrict myArray ///< Array to free 213 ); 214 215 216 217 218 219 220 155 221 156 222 /** An array of complex numbers. … … 182 248 183 249 184 /************************************************************************************************************/ 185 186 /** An array of double-precision real numbers */ 187 typedef struct 188 { 189 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 190 int nalloc; ///< Total number of elements available 191 int n; ///< Number of elements in use 192 double *arr; ///< The array data 193 } 194 psDoubleArray; 195 196 /** Constructor \ingroup DataGroup */ 197 psDoubleArray *psDoubleArrayAlloc(int nalloc) ///< Total number of elements to make available 198 ; 199 200 /** Reallocator \ingroup DataGroup */ 201 psDoubleArray *psDoubleArrayRealloc(psDoubleArray *myArray, ///< Array to reallocate 202 int nalloc) ///< Total number of elements to make available 203 ; 204 205 /** Destructor \ingroup DataGroup */ 206 void psDoubleArrayFree(psDoubleArray *restrict myArray) ///< Array to free 207 ; 250 208 251 209 252 /** Array of pointers to void. -
trunk/psLib/src/collections/psSort.c
r485 r486 14 14 * @author Ross Harman, MHPCC 15 15 * 16 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $17 * @date $Date: 2004-04-21 00: 18:05$16 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2004-04-21 00:40:32 $ 18 18 * 19 19 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 187 187 } 188 188 189 tmpFloatArray = psFloatArrayAlloc(inN , inN);189 tmpFloatArray = psFloatArrayAlloc(inN); 190 190 tmpFloatArray = psSort(tmpFloatArray, inArray); 191 191 -
trunk/psLib/src/types/psArray.c
r485 r486 8 8 * @author Ross Harman, MHPCC 9 9 * 10 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-04-21 00: 18:05$10 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-04-21 00:40:32 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 #include "psMemory.h" 20 20 #include "psArray.h" 21 #include "psLogMsg.h"22 21 23 22 /******************************************************************************/ … … 54 53 /* FUNCTION IMPLEMENTATION - PUBLIC */ 55 54 /*****************************************************************************/ 55 56 psIntArray* psIntArrayAlloc(int nalloc) 57 { 58 psIntArray *psArr = (psIntArray*)p_psAlloc(sizeof(psIntArray), __FILE__, __LINE__); 59 psArr->type.dimen = PS_DIMEN_VECTOR; 60 psArr->type.type = PS_TYPE_INT; 61 psArr->nalloc = nalloc; 62 psArr->n = 0; 63 64 if(nalloc == 0) { 65 psArr->arr = NULL; 66 } else { 67 psArr->arr = p_psAlloc(nalloc*sizeof(int), __FILE__, __LINE__); 68 } 69 70 return psArr; 71 } 72 73 psIntArray *psIntArrayRealloc(psIntArray *psArr, int nalloc) 74 { 75 if(psArr == NULL) { 76 return psIntArrayAlloc(nalloc); 77 } 78 if(nalloc <= psArr->nalloc) { 79 if (psArr->n < nalloc) { 80 psArr->n = nalloc; 81 } 82 } else { 83 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof(int), __FILE__, __LINE__); 84 psArr->nalloc = nalloc; 85 } 86 return psArr; 87 } 88 89 void psIntArrayFree(psIntArray *restrict psArr) 90 { 91 if (psArr == NULL) { 92 return; 93 } 94 p_psFree(psArr->arr, __FILE__, __LINE__); 95 p_psFree(psArr, __FILE__, __LINE__); 96 } 56 97 57 98 psFloatArray* psFloatArrayAlloc(int nalloc) … … 97 138 } 98 139 99 ps IntArray* psIntArrayAlloc(int nalloc)140 psDoubleArray* psDoubleArrayAlloc(int nalloc) 100 141 { 101 ps IntArray *psArr = (psIntArray*)p_psAlloc(sizeof(psIntArray), __FILE__, __LINE__);142 psDoubleArray *psArr = (psDoubleArray*)p_psAlloc(sizeof(psDoubleArray), __FILE__, __LINE__); 102 143 psArr->type.dimen = PS_DIMEN_VECTOR; 103 psArr->type.type = PS_TYPE_ INT;144 psArr->type.type = PS_TYPE_DOUBLE; 104 145 psArr->nalloc = nalloc; 105 146 psArr->n = 0; … … 108 149 psArr->arr = NULL; 109 150 } else { 110 psArr->arr = p_psAlloc(nalloc*sizeof( int), __FILE__, __LINE__);151 psArr->arr = p_psAlloc(nalloc*sizeof(double), __FILE__, __LINE__); 111 152 } 112 153 … … 114 155 } 115 156 116 ps IntArray *psIntArrayRealloc(psIntArray *psArr, int nalloc)157 psDoubleArray *psDoubleArrayRealloc(psDoubleArray *psArr, int nalloc) 117 158 { 118 159 if(psArr == NULL) { 119 return ps IntArrayAlloc(nalloc);160 return psDoubleArrayAlloc(nalloc); 120 161 } 121 162 if(nalloc <= psArr->nalloc) { … … 124 165 } 125 166 } else { 126 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof( int), __FILE__, __LINE__);167 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof(double), __FILE__, __LINE__); 127 168 psArr->nalloc = nalloc; 128 169 } … … 130 171 } 131 172 132 void ps IntArrayFree(psIntArray *restrict psArr)173 void psDoubleArrayFree(psDoubleArray *restrict psArr) 133 174 { 134 175 if (psArr == NULL) { -
trunk/psLib/src/types/psArray.h
r485 r486 8 8 * @author Ross Harman, MHPCC 9 9 * 10 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-04-21 00: 18:05$10 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-04-21 00:40:32 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 96 96 typedef struct 97 97 { 98 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT!99 int nalloc; ///< Total number of elements available.100 int n; ///< Number of elements in use.101 float *arr; ///< Array data.98 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 99 int nalloc; ///< Total number of elements available. 100 int n; ///< Number of elements in use. 101 float *arr; ///< Array data. 102 102 } 103 103 psFloatArray; 104 105 /** An array of doubles. 106 * 107 * Struct for maintaining an array of double precision floating point numbers. 108 * 109 */ 110 typedef struct 111 { 112 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 113 int nalloc; ///< Total number of elements available. 114 int n; ///< Number of elements in use. 115 double *arr; ///< Array data. 116 } 117 psDoubleArray; 104 118 105 119 /*****************************************************************************/ … … 107 121 /*****************************************************************************/ 108 122 109 /** Allocate an integer array */ 123 /** Allocate an integer array. 124 * 125 * Uses psLib memory allocation functions to create an array of integers as defined by the psIntArray struct. 126 * 127 */ 110 128 psIntArray *psIntArrayAlloc( 111 129 int nalloc ///< Total number of elements to make available 112 130 ); 113 131 114 /** Reallocate an integer array */ 132 /** Reallocate an integer array. 133 * 134 * Uses psLib memory allocation functions to reallocate an array of integers as defined by the psIntArray 135 * struct. 136 * 137 */ 115 138 psIntArray *psIntArrayRealloc( 116 139 psIntArray *myArray, ///< Array to reallocate. … … 119 142 120 143 121 /** Deallocate an integer array */ 144 /** Deallocate an integer array 145 * 146 * Uses psLib memory allocation functions to deallocate an array of integers as defined by the psIntArray 147 * struct. 148 * 149 */ 122 150 void psIntArrayFree( 123 151 psIntArray *restrict myArray ///< Array to free … … 153 181 psFloatArray *restrict myArray ///< Array to free 154 182 ); 183 184 /** Allocate a Double array. 185 * 186 * Uses psLib memory allocation functions to create an array of doubles as defined by the psDoubleArray 187 * struct. 188 * 189 */ 190 psDoubleArray *psDoubleArrayAlloc( 191 int nalloc ///< Total number of elements to make available. 192 ); 193 194 /** Reallocate a Double array. 195 * 196 * Uses psLib memory allocation functions to reallocate an array of Doubles as defined by the psDoubleArray 197 * struct. 198 * 199 */ 200 psDoubleArray *psDoubleArrayRealloc( 201 psDoubleArray *myArray, ///< Array to reallocate. 202 int nalloc ///< Total number of elements to make available. 203 ); 204 205 /** Deallocate a Double array 206 * 207 * Uses psLib memory allocation functions to deallocate an array of doubles as defined by the psDoubleArray 208 * struct. 209 * 210 */ 211 void psDoubleArrayFree( 212 psDoubleArray *restrict myArray ///< Array to free 213 ); 214 215 216 217 218 219 220 155 221 156 222 /** An array of complex numbers. … … 182 248 183 249 184 /************************************************************************************************************/ 185 186 /** An array of double-precision real numbers */ 187 typedef struct 188 { 189 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 190 int nalloc; ///< Total number of elements available 191 int n; ///< Number of elements in use 192 double *arr; ///< The array data 193 } 194 psDoubleArray; 195 196 /** Constructor \ingroup DataGroup */ 197 psDoubleArray *psDoubleArrayAlloc(int nalloc) ///< Total number of elements to make available 198 ; 199 200 /** Reallocator \ingroup DataGroup */ 201 psDoubleArray *psDoubleArrayRealloc(psDoubleArray *myArray, ///< Array to reallocate 202 int nalloc) ///< Total number of elements to make available 203 ; 204 205 /** Destructor \ingroup DataGroup */ 206 void psDoubleArrayFree(psDoubleArray *restrict myArray) ///< Array to free 207 ; 250 208 251 209 252 /** Array of pointers to void.
Note:
See TracChangeset
for help on using the changeset viewer.
