Changeset 485
- Timestamp:
- Apr 20, 2004, 2:18:05 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 6 edited
-
collections/Makefile (modified) (2 diffs)
-
collections/psArray.c (modified) (1 diff)
-
collections/psArray.h (modified) (1 diff)
-
collections/psSort.c (modified) (10 diffs)
-
types/psArray.c (modified) (1 diff)
-
types/psArray.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/Makefile
r438 r485 13 13 psBitMask.o \ 14 14 psSort.o \ 15 psArray.o 15 16 16 17 INCLUDES = -I$(includedir) … … 18 19 %.o: %.c 19 20 @echo " Compiling $<. " 20 $(CC) $(CFLAGS) $(INCLUDE_GLOBAL) $(INCLUDES) -c $< -o $@21 $(CC) $(CFLAGS) -DPS_ALLOW_MALLOC $(INCLUDE_GLOBAL) $(INCLUDES) -c $< -o $@ 21 22 22 23 libpsCollections.a: $(SRC_OBJS) -
trunk/psLib/src/collections/psArray.c
r433 r485 1 /* remove this file when there is a valid psArray.h */ 1 /** @file psArray.c 2 * 3 * @brief Contains support for array types 4 * 5 * The type of basic one dimensional arrays are defined here include: int, float, double, complex float, and 6 * void *. 7 * 8 * @author Ross Harman, MHPCC 9 * 10 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-04-21 00:18:05 $ 12 * 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 14 */ 2 15 16 /******************************************************************************/ 17 /* INCLUDE FILES */ 18 /******************************************************************************/ 19 #include "psMemory.h" 3 20 #include "psArray.h" 21 #include "psLogMsg.h" 4 22 5 #include <stdlib.h> 23 /******************************************************************************/ 24 /* DEFINE STATEMENTS */ 25 /******************************************************************************/ 6 26 7 psFloatArray *psFloatArrayAlloc(int nalloc) 27 // None 28 29 /******************************************************************************/ 30 /* TYPE DEFINITIONS */ 31 /******************************************************************************/ 32 33 // None 34 35 /*****************************************************************************/ 36 /* GLOBAL VARIABLES */ 37 /*****************************************************************************/ 38 39 // None 40 41 /*****************************************************************************/ 42 /* FILE STATIC VARIABLES */ 43 /*****************************************************************************/ 44 45 // None 46 47 /*****************************************************************************/ 48 /* FUNCTION IMPLEMENTATION - LOCAL */ 49 /*****************************************************************************/ 50 51 // None 52 53 /*****************************************************************************/ 54 /* FUNCTION IMPLEMENTATION - PUBLIC */ 55 /*****************************************************************************/ 56 57 psFloatArray* psFloatArrayAlloc(int nalloc) 8 58 { 9 psFloatArray *psArray = (psFloatArray*)malloc(sizeof(psFloatArray)); 10 psArray->n = nalloc; 11 psArray->arr = (float*)malloc(sizeof(float)*nalloc); 12 13 return psArray; 59 psFloatArray *psArr = (psFloatArray*)p_psAlloc(sizeof(psFloatArray), __FILE__, __LINE__); 60 psArr->type.dimen = PS_DIMEN_VECTOR; 61 psArr->type.type = PS_TYPE_FLOAT; 62 psArr->nalloc = nalloc; 63 psArr->n = 0; 64 65 if(nalloc == 0) { 66 psArr->arr = NULL; 67 } else { 68 psArr->arr = p_psAlloc(nalloc*sizeof(float), __FILE__, __LINE__); 69 } 70 71 return psArr; 14 72 } 15 73 16 int psFreeFloatArray(psFloatArray *inArray)74 psFloatArray *psFloatArrayRealloc(psFloatArray *psArr, int nalloc) 17 75 { 18 free(inArray->arr); 19 free(inArray); 20 return 0; 76 if(psArr == NULL) { 77 return psFloatArrayAlloc(nalloc); 78 } 79 if(nalloc <= psArr->nalloc) { 80 if (psArr->n < nalloc) { 81 psArr->n = nalloc; 82 } 83 } else { 84 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof(float), __FILE__, __LINE__); 85 psArr->nalloc = nalloc; 86 } 87 return psArr; 21 88 } 22 89 23 psIntArray *psIntArrayAlloc(int nalloc)90 void psFloatArrayFree(psFloatArray *restrict psArr) 24 91 { 25 psIntArray *psArray = (psIntArray*)malloc(sizeof(psIntArray));26 psArray->n = nalloc;27 psArray->arr = (int*)malloc(sizeof(int)*nalloc);28 29 return psArray;92 if (psArr == NULL) { 93 return; 94 } 95 p_psFree(psArr->arr, __FILE__, __LINE__); 96 p_psFree(psArr, __FILE__, __LINE__); 30 97 } 98 99 psIntArray* psIntArrayAlloc(int nalloc) 100 { 101 psIntArray *psArr = (psIntArray*)p_psAlloc(sizeof(psIntArray), __FILE__, __LINE__); 102 psArr->type.dimen = PS_DIMEN_VECTOR; 103 psArr->type.type = PS_TYPE_INT; 104 psArr->nalloc = nalloc; 105 psArr->n = 0; 106 107 if(nalloc == 0) { 108 psArr->arr = NULL; 109 } else { 110 psArr->arr = p_psAlloc(nalloc*sizeof(int), __FILE__, __LINE__); 111 } 112 113 return psArr; 114 } 115 116 psIntArray *psIntArrayRealloc(psIntArray *psArr, int nalloc) 117 { 118 if(psArr == NULL) { 119 return psIntArrayAlloc(nalloc); 120 } 121 if(nalloc <= psArr->nalloc) { 122 if (psArr->n < nalloc) { 123 psArr->n = nalloc; 124 } 125 } else { 126 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof(int), __FILE__, __LINE__); 127 psArr->nalloc = nalloc; 128 } 129 return psArr; 130 } 131 132 void psIntArrayFree(psIntArray *restrict psArr) 133 { 134 if (psArr == NULL) { 135 return; 136 } 137 p_psFree(psArr->arr, __FILE__, __LINE__); 138 p_psFree(psArr, __FILE__, __LINE__); 139 } -
trunk/psLib/src/collections/psArray.h
r433 r485 1 /* remove this file when there is a valid psArray.h */ 2 3 typedef struct { 4 int n; 5 float *arr; 6 } psFloatArray; 7 8 typedef struct { 9 int n; 10 int *arr; 11 } psIntArray; 12 13 psFloatArray *psFloatArrayAlloc(int nalloc); 14 int psFreeFloatArray(psFloatArray *inArray); 15 psIntArray *psIntArrayAlloc(int nalloc); 1 /** @file psArray.h 2 * 3 * @brief Contains support for basic array types 4 * 5 * The types of basic one dimensional arrays defined include: int, float, double, complex float, and 6 * void *. 7 * 8 * @author Ross Harman, MHPCC 9 * 10 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-04-21 00:18:05 $ 12 * 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 14 */ 15 16 #ifndef PS_ARRAY_H 17 #define PS_ARRAY_H 18 19 #include <complex.h> 20 21 /******************************************************************************/ 22 /* DEFINE STATEMENTS */ 23 /******************************************************************************/ 24 25 // None 26 27 /******************************************************************************/ 28 /* TYPE DEFINITIONS */ 29 /******************************************************************************/ 30 31 /** Types of the elements of vectors, images, etc. 32 * 33 * The basic types of the primitives used by psLib are defined within this enum. This enum is used by the psType struct. 34 * 35 */ 36 typedef enum { 37 PS_TYPE_CHAR, ///< Character. 38 PS_TYPE_SHORT, ///< Short integer. 39 PS_TYPE_INT, ///< Integer. 40 PS_TYPE_LONG, ///< Long integer. 41 PS_TYPE_UCHAR, ///< Unsigned character. 42 PS_TYPE_USHORT, ///< Unsigned short integer. 43 PS_TYPE_UINT, ///< Unsigned integer. 44 PS_TYPE_ULONG, ///< Unsigned long integer. 45 PS_TYPE_FLOAT, ///< Floating point. 46 PS_TYPE_DOUBLE, ///< Double-precision floating point. 47 PS_TYPE_COMPLEX, ///< Complex numbers consisting of floating point. 48 PS_TYPE_OTHER, ///< Something else that's not supported for arithmetic. 49 } psElemType; 50 51 /** Dimensions of a data type. 52 * 53 * The dimensions of containers used by psLib are defined within this enum. This enum is used by the psType struct. 54 * 55 */ 56 typedef enum { 57 PS_DIMEN_SCALAR, ///< Scalar. 58 PS_DIMEN_VECTOR, ///< Vector. 59 PS_DIMEN_TRANSV, ///< Transposed vector. 60 PS_DIMEN_IMAGE, ///< Image. 61 PS_DIMEN_OTHER ///< Something else that's not supported for arithmetic. 62 } psDimen; 63 64 /** The type of a data type. 65 * 66 * All psLib complex types consist of primitive components. This struct provides the description of those 67 * primitives. 68 * 69 */ 70 typedef struct 71 { 72 psElemType type; ///< Primitive type. 73 psDimen dimen; ///< Dimensionality. 74 } 75 psType; 76 77 /** An array of integers. 78 * 79 * Struct for maintaining an array of integer numbers. 80 * 81 */ 82 typedef struct 83 { 84 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 85 int nalloc; ///< Total number of elements available. 86 int n; ///< Number of elements in use. 87 int *arr; ///< Array data. 88 } 89 psIntArray; 90 91 /** An array of floats. 92 * 93 * Struct for maintaining an array of floating point numbers. 94 * 95 */ 96 typedef struct 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. 102 } 103 psFloatArray; 104 105 /*****************************************************************************/ 106 /* FUNCTION PROTOTYPES */ 107 /*****************************************************************************/ 108 109 /** Allocate an integer array */ 110 psIntArray *psIntArrayAlloc( 111 int nalloc ///< Total number of elements to make available 112 ); 113 114 /** Reallocate an integer array */ 115 psIntArray *psIntArrayRealloc( 116 psIntArray *myArray, ///< Array to reallocate. 117 int nalloc ///< Total number of elements to make available. 118 ); 119 120 121 /** Deallocate an integer array */ 122 void psIntArrayFree( 123 psIntArray *restrict myArray ///< Array to free 124 ); 125 126 /** Allocate a float array. 127 * 128 * Uses psLib memory allocation functions to create an array of floats as defined by the psFloatArray struct. 129 * 130 */ 131 psFloatArray *psFloatArrayAlloc( 132 int nalloc ///< Total number of elements to make available. 133 ); 134 135 /** Reallocate a float array. 136 * 137 * Uses psLib memory allocation functions to reallocate an array of floats as defined by the psFloatArray 138 * struct. 139 * 140 */ 141 psFloatArray *psFloatArrayRealloc( 142 psFloatArray *myArray, ///< Array to reallocate. 143 int nalloc ///< Total number of elements to make available. 144 ); 145 146 /** Deallocate a float array 147 * 148 * Uses psLib memory allocation functions to deallocate an array of floats as defined by the psFloatArray 149 * struct. 150 * 151 */ 152 void psFloatArrayFree( 153 psFloatArray *restrict myArray ///< Array to free 154 ); 155 156 /** An array of complex numbers. 157 * 158 * Struct for maintaining an array of complex numbers. 159 * 160 */ 161 typedef struct 162 { 163 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 164 int size; ///< Total number of elements available. 165 int n; ///< Number of elements in use 166 complex float *arr; ///< Array data. 167 } 168 psComplexArray; 169 170 /** Constructor \ingroup DataGroup */ 171 psComplexArray *psComplexArrayAlloc(int nalloc) ///< Total number of elements to make available 172 ; 173 174 /** Reallocator \ingroup DataGroup */ 175 psComplexArray *psComplexArrayRealloc(psComplexArray *myArray, ///< Array to reallocate 176 int nalloc) ///< Total number of elements to make available 177 ; 178 179 /** Destructor \ingroup DataGroup */ 180 void psComplexArrayFree(psComplexArray *restrict myArray) ///< Array to free 181 ; 182 183 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 ; 208 209 /** Array of pointers to void. 210 * psVoidPtrArray is special, as it needs to have a destructor that 211 * accepts a destructor for the array elements 212 */ 213 typedef struct 214 { 215 int n; ///< Number of elements in use 216 int nalloc; ///< Number of total elements 217 void **arr; ///< The elements 218 } 219 psVoidPtrArray; 220 221 /** Constructor \ingroup DataGroup */ 222 psVoidPtrArray *psVoidPtrArrayAlloc(int nalloc) ///< Number of elements to use 223 ; 224 225 /** Reallocate \ingroup DataGroup */ 226 psVoidPtrArray *psVoidPtrArrayRealloc(psVoidPtrArray *arr, ///< Array to reallocate 227 int nalloc) ///< Number of elements 228 ; 229 230 /** Destructor \ingroup DataGroup */ 231 void psVoidPtrArrayFree(psVoidPtrArray *arr, ///< array to destroy 232 void (*elemFree)(void *)) ///< destructor for array data 233 ; 234 235 #endif -
trunk/psLib/src/collections/psSort.c
r450 r485 14 14 * @author Ross Harman, MHPCC 15 15 * 16 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $17 * @date $Date: 2004-04- 19 20:10:46$16 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2004-04-21 00:18:05 $ 18 18 * 19 19 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 22 /******************************************************************************/ 23 23 /* INCLUDE FILES */ 24 /******************************************************************************/ 24 /******************************************************************************/ 25 25 26 26 #include <stdio.h> … … 71 71 * @return int: Result of comparsion (-1, 0, or 1). 72 72 */ 73 73 74 74 static int psCompare( 75 75 const void *x, /**< First float to compare. */ … … 79 79 float *item1 = NULL; 80 80 float *item2 = NULL; 81 81 82 82 if(x == NULL || y == NULL) { 83 83 psError(__func__, " : Line %d - Null input argument: x=%d y=%d\n", __LINE__, x, y); 84 84 } 85 85 86 86 item1 = (float*)x; 87 87 item2 = (float*)y; 88 88 89 89 if(item1 == NULL || item2 == NULL) { 90 90 psError(__func__, " : Line %d - Improper cast to float: item1=%d item2=%d\n", __LINE__, item1, item2); 91 91 } 92 92 93 93 if(*item1 < *item2) { 94 94 return -1; 95 } 96 else if(*item1 > *item2) { 95 } else if(*item1 > *item2) { 97 96 return 1; 98 } 99 else { 97 } else { 100 98 return 0; 101 99 } … … 122 120 return outArray; 123 121 } 124 122 125 123 if(inArray == NULL) { 126 124 psError(__func__, " : Line %d - Null input array\n", __LINE__); 127 125 return outArray; 128 126 } 129 127 130 128 // Initialize values 131 129 inN = inArray->n; … … 134 132 outArr = outArray->arr; 135 133 elSize = sizeof(float); 136 134 137 135 if(inN != outN) { 138 136 psError(__func__, " : Line %d - Input and output array sizes are not equal: in=%d out=%d\n", __LINE__, … … 140 138 return outArray; 141 139 } 142 140 143 141 // Copy input array values into output array 144 142 for(i=0; i<inN; i++) { 145 143 outArr[i] = inArr[i]; 146 144 } 147 145 148 146 // Sort output array 149 147 qsort((void*)outArr, inN, elSize, psCompare); 150 148 151 149 return outArray; 152 150 } … … 166 164 float diff = 0.0f; 167 165 psFloatArray *tmpFloatArray = NULL; 168 166 169 167 if(outArray == NULL) { 170 168 psError(__func__, " : Line %d - Null output array\n", __LINE__); 171 169 return outArray; 172 170 } 173 171 174 172 if(inArray == NULL) { 175 173 psError(__func__, " : Line %d - Null input array\n", __LINE__); … … 189 187 } 190 188 191 tmpFloatArray = psFloatArrayAlloc(inN );189 tmpFloatArray = psFloatArrayAlloc(inN, inN); 192 190 tmpFloatArray = psSort(tmpFloatArray, inArray); 193 191 194 192 for(i=0; i<inN; i++) { 195 193 tempVal = tmpFloatArray->arr[i]; … … 200 198 break; 201 199 } 202 } 203 } 204 200 } 201 } 202 205 203 // Free temp memory 206 psF reeFloatArray(tmpFloatArray);207 208 return outArray; 204 psFloatArrayFree(tmpFloatArray); 205 206 return outArray; 209 207 } -
trunk/psLib/src/types/psArray.c
r433 r485 1 /* remove this file when there is a valid psArray.h */ 1 /** @file psArray.c 2 * 3 * @brief Contains support for array types 4 * 5 * The type of basic one dimensional arrays are defined here include: int, float, double, complex float, and 6 * void *. 7 * 8 * @author Ross Harman, MHPCC 9 * 10 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-04-21 00:18:05 $ 12 * 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 14 */ 2 15 16 /******************************************************************************/ 17 /* INCLUDE FILES */ 18 /******************************************************************************/ 19 #include "psMemory.h" 3 20 #include "psArray.h" 21 #include "psLogMsg.h" 4 22 5 #include <stdlib.h> 23 /******************************************************************************/ 24 /* DEFINE STATEMENTS */ 25 /******************************************************************************/ 6 26 7 psFloatArray *psFloatArrayAlloc(int nalloc) 27 // None 28 29 /******************************************************************************/ 30 /* TYPE DEFINITIONS */ 31 /******************************************************************************/ 32 33 // None 34 35 /*****************************************************************************/ 36 /* GLOBAL VARIABLES */ 37 /*****************************************************************************/ 38 39 // None 40 41 /*****************************************************************************/ 42 /* FILE STATIC VARIABLES */ 43 /*****************************************************************************/ 44 45 // None 46 47 /*****************************************************************************/ 48 /* FUNCTION IMPLEMENTATION - LOCAL */ 49 /*****************************************************************************/ 50 51 // None 52 53 /*****************************************************************************/ 54 /* FUNCTION IMPLEMENTATION - PUBLIC */ 55 /*****************************************************************************/ 56 57 psFloatArray* psFloatArrayAlloc(int nalloc) 8 58 { 9 psFloatArray *psArray = (psFloatArray*)malloc(sizeof(psFloatArray)); 10 psArray->n = nalloc; 11 psArray->arr = (float*)malloc(sizeof(float)*nalloc); 12 13 return psArray; 59 psFloatArray *psArr = (psFloatArray*)p_psAlloc(sizeof(psFloatArray), __FILE__, __LINE__); 60 psArr->type.dimen = PS_DIMEN_VECTOR; 61 psArr->type.type = PS_TYPE_FLOAT; 62 psArr->nalloc = nalloc; 63 psArr->n = 0; 64 65 if(nalloc == 0) { 66 psArr->arr = NULL; 67 } else { 68 psArr->arr = p_psAlloc(nalloc*sizeof(float), __FILE__, __LINE__); 69 } 70 71 return psArr; 14 72 } 15 73 16 int psFreeFloatArray(psFloatArray *inArray)74 psFloatArray *psFloatArrayRealloc(psFloatArray *psArr, int nalloc) 17 75 { 18 free(inArray->arr); 19 free(inArray); 20 return 0; 76 if(psArr == NULL) { 77 return psFloatArrayAlloc(nalloc); 78 } 79 if(nalloc <= psArr->nalloc) { 80 if (psArr->n < nalloc) { 81 psArr->n = nalloc; 82 } 83 } else { 84 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof(float), __FILE__, __LINE__); 85 psArr->nalloc = nalloc; 86 } 87 return psArr; 21 88 } 22 89 23 psIntArray *psIntArrayAlloc(int nalloc)90 void psFloatArrayFree(psFloatArray *restrict psArr) 24 91 { 25 psIntArray *psArray = (psIntArray*)malloc(sizeof(psIntArray));26 psArray->n = nalloc;27 psArray->arr = (int*)malloc(sizeof(int)*nalloc);28 29 return psArray;92 if (psArr == NULL) { 93 return; 94 } 95 p_psFree(psArr->arr, __FILE__, __LINE__); 96 p_psFree(psArr, __FILE__, __LINE__); 30 97 } 98 99 psIntArray* psIntArrayAlloc(int nalloc) 100 { 101 psIntArray *psArr = (psIntArray*)p_psAlloc(sizeof(psIntArray), __FILE__, __LINE__); 102 psArr->type.dimen = PS_DIMEN_VECTOR; 103 psArr->type.type = PS_TYPE_INT; 104 psArr->nalloc = nalloc; 105 psArr->n = 0; 106 107 if(nalloc == 0) { 108 psArr->arr = NULL; 109 } else { 110 psArr->arr = p_psAlloc(nalloc*sizeof(int), __FILE__, __LINE__); 111 } 112 113 return psArr; 114 } 115 116 psIntArray *psIntArrayRealloc(psIntArray *psArr, int nalloc) 117 { 118 if(psArr == NULL) { 119 return psIntArrayAlloc(nalloc); 120 } 121 if(nalloc <= psArr->nalloc) { 122 if (psArr->n < nalloc) { 123 psArr->n = nalloc; 124 } 125 } else { 126 psArr->arr = p_psRealloc(psArr->arr, nalloc*sizeof(int), __FILE__, __LINE__); 127 psArr->nalloc = nalloc; 128 } 129 return psArr; 130 } 131 132 void psIntArrayFree(psIntArray *restrict psArr) 133 { 134 if (psArr == NULL) { 135 return; 136 } 137 p_psFree(psArr->arr, __FILE__, __LINE__); 138 p_psFree(psArr, __FILE__, __LINE__); 139 } -
trunk/psLib/src/types/psArray.h
r433 r485 1 /* remove this file when there is a valid psArray.h */ 2 3 typedef struct { 4 int n; 5 float *arr; 6 } psFloatArray; 7 8 typedef struct { 9 int n; 10 int *arr; 11 } psIntArray; 12 13 psFloatArray *psFloatArrayAlloc(int nalloc); 14 int psFreeFloatArray(psFloatArray *inArray); 15 psIntArray *psIntArrayAlloc(int nalloc); 1 /** @file psArray.h 2 * 3 * @brief Contains support for basic array types 4 * 5 * The types of basic one dimensional arrays defined include: int, float, double, complex float, and 6 * void *. 7 * 8 * @author Ross Harman, MHPCC 9 * 10 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-04-21 00:18:05 $ 12 * 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 14 */ 15 16 #ifndef PS_ARRAY_H 17 #define PS_ARRAY_H 18 19 #include <complex.h> 20 21 /******************************************************************************/ 22 /* DEFINE STATEMENTS */ 23 /******************************************************************************/ 24 25 // None 26 27 /******************************************************************************/ 28 /* TYPE DEFINITIONS */ 29 /******************************************************************************/ 30 31 /** Types of the elements of vectors, images, etc. 32 * 33 * The basic types of the primitives used by psLib are defined within this enum. This enum is used by the psType struct. 34 * 35 */ 36 typedef enum { 37 PS_TYPE_CHAR, ///< Character. 38 PS_TYPE_SHORT, ///< Short integer. 39 PS_TYPE_INT, ///< Integer. 40 PS_TYPE_LONG, ///< Long integer. 41 PS_TYPE_UCHAR, ///< Unsigned character. 42 PS_TYPE_USHORT, ///< Unsigned short integer. 43 PS_TYPE_UINT, ///< Unsigned integer. 44 PS_TYPE_ULONG, ///< Unsigned long integer. 45 PS_TYPE_FLOAT, ///< Floating point. 46 PS_TYPE_DOUBLE, ///< Double-precision floating point. 47 PS_TYPE_COMPLEX, ///< Complex numbers consisting of floating point. 48 PS_TYPE_OTHER, ///< Something else that's not supported for arithmetic. 49 } psElemType; 50 51 /** Dimensions of a data type. 52 * 53 * The dimensions of containers used by psLib are defined within this enum. This enum is used by the psType struct. 54 * 55 */ 56 typedef enum { 57 PS_DIMEN_SCALAR, ///< Scalar. 58 PS_DIMEN_VECTOR, ///< Vector. 59 PS_DIMEN_TRANSV, ///< Transposed vector. 60 PS_DIMEN_IMAGE, ///< Image. 61 PS_DIMEN_OTHER ///< Something else that's not supported for arithmetic. 62 } psDimen; 63 64 /** The type of a data type. 65 * 66 * All psLib complex types consist of primitive components. This struct provides the description of those 67 * primitives. 68 * 69 */ 70 typedef struct 71 { 72 psElemType type; ///< Primitive type. 73 psDimen dimen; ///< Dimensionality. 74 } 75 psType; 76 77 /** An array of integers. 78 * 79 * Struct for maintaining an array of integer numbers. 80 * 81 */ 82 typedef struct 83 { 84 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 85 int nalloc; ///< Total number of elements available. 86 int n; ///< Number of elements in use. 87 int *arr; ///< Array data. 88 } 89 psIntArray; 90 91 /** An array of floats. 92 * 93 * Struct for maintaining an array of floating point numbers. 94 * 95 */ 96 typedef struct 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. 102 } 103 psFloatArray; 104 105 /*****************************************************************************/ 106 /* FUNCTION PROTOTYPES */ 107 /*****************************************************************************/ 108 109 /** Allocate an integer array */ 110 psIntArray *psIntArrayAlloc( 111 int nalloc ///< Total number of elements to make available 112 ); 113 114 /** Reallocate an integer array */ 115 psIntArray *psIntArrayRealloc( 116 psIntArray *myArray, ///< Array to reallocate. 117 int nalloc ///< Total number of elements to make available. 118 ); 119 120 121 /** Deallocate an integer array */ 122 void psIntArrayFree( 123 psIntArray *restrict myArray ///< Array to free 124 ); 125 126 /** Allocate a float array. 127 * 128 * Uses psLib memory allocation functions to create an array of floats as defined by the psFloatArray struct. 129 * 130 */ 131 psFloatArray *psFloatArrayAlloc( 132 int nalloc ///< Total number of elements to make available. 133 ); 134 135 /** Reallocate a float array. 136 * 137 * Uses psLib memory allocation functions to reallocate an array of floats as defined by the psFloatArray 138 * struct. 139 * 140 */ 141 psFloatArray *psFloatArrayRealloc( 142 psFloatArray *myArray, ///< Array to reallocate. 143 int nalloc ///< Total number of elements to make available. 144 ); 145 146 /** Deallocate a float array 147 * 148 * Uses psLib memory allocation functions to deallocate an array of floats as defined by the psFloatArray 149 * struct. 150 * 151 */ 152 void psFloatArrayFree( 153 psFloatArray *restrict myArray ///< Array to free 154 ); 155 156 /** An array of complex numbers. 157 * 158 * Struct for maintaining an array of complex numbers. 159 * 160 */ 161 typedef struct 162 { 163 psType type; ///< Type of data. THIS STRUCT ELEMENT MUST BE FIRST IN THE STRUCT! 164 int size; ///< Total number of elements available. 165 int n; ///< Number of elements in use 166 complex float *arr; ///< Array data. 167 } 168 psComplexArray; 169 170 /** Constructor \ingroup DataGroup */ 171 psComplexArray *psComplexArrayAlloc(int nalloc) ///< Total number of elements to make available 172 ; 173 174 /** Reallocator \ingroup DataGroup */ 175 psComplexArray *psComplexArrayRealloc(psComplexArray *myArray, ///< Array to reallocate 176 int nalloc) ///< Total number of elements to make available 177 ; 178 179 /** Destructor \ingroup DataGroup */ 180 void psComplexArrayFree(psComplexArray *restrict myArray) ///< Array to free 181 ; 182 183 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 ; 208 209 /** Array of pointers to void. 210 * psVoidPtrArray is special, as it needs to have a destructor that 211 * accepts a destructor for the array elements 212 */ 213 typedef struct 214 { 215 int n; ///< Number of elements in use 216 int nalloc; ///< Number of total elements 217 void **arr; ///< The elements 218 } 219 psVoidPtrArray; 220 221 /** Constructor \ingroup DataGroup */ 222 psVoidPtrArray *psVoidPtrArrayAlloc(int nalloc) ///< Number of elements to use 223 ; 224 225 /** Reallocate \ingroup DataGroup */ 226 psVoidPtrArray *psVoidPtrArrayRealloc(psVoidPtrArray *arr, ///< Array to reallocate 227 int nalloc) ///< Number of elements 228 ; 229 230 /** Destructor \ingroup DataGroup */ 231 void psVoidPtrArrayFree(psVoidPtrArray *arr, ///< array to destroy 232 void (*elemFree)(void *)) ///< destructor for array data 233 ; 234 235 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
