IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 485


Ignore:
Timestamp:
Apr 20, 2004, 2:18:05 PM (22 years ago)
Author:
harman
Message:

Added Integer array

Location:
trunk/psLib/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/Makefile

    r438 r485  
    1313    psBitMask.o \
    1414    psSort.o \
     15    psArray.o
    1516
    1617INCLUDES = -I$(includedir)
     
    1819%.o: %.c
    1920        @echo "    Compiling $<. "
    20         $(CC) $(CFLAGS) $(INCLUDE_GLOBAL) $(INCLUDES) -c $< -o $@
     21        $(CC) $(CFLAGS) -DPS_ALLOW_MALLOC $(INCLUDE_GLOBAL) $(INCLUDES) -c $< -o $@
    2122
    2223libpsCollections.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 */
    215
     16/******************************************************************************/
     17/*  INCLUDE FILES                                                             */
     18/******************************************************************************/
     19#include "psMemory.h"
    320#include "psArray.h"
     21#include "psLogMsg.h"
    422
    5 #include <stdlib.h>
     23/******************************************************************************/
     24/*  DEFINE STATEMENTS                                                         */
     25/******************************************************************************/
    626
    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
     57psFloatArray* psFloatArrayAlloc(int nalloc)
    858{
    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;
    1472}
    1573
    16 int psFreeFloatArray(psFloatArray *inArray)
     74psFloatArray *psFloatArrayRealloc(psFloatArray *psArr, int nalloc)
    1775{
    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;
    2188}
    2289
    23 psIntArray *psIntArrayAlloc(int nalloc)
     90void psFloatArrayFree(psFloatArray *restrict psArr)
    2491{
    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__);
    3097}
     98
     99psIntArray* 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
     116psIntArray *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
     132void 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 */
     36typedef 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 */
     56typedef 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 */
     70typedef struct
     71{
     72    psElemType type;  ///< Primitive type.
     73    psDimen dimen;   ///< Dimensionality.
     74}
     75psType;
     76
     77/** An array of integers.
     78 *
     79 * Struct for maintaining an array of integer numbers.
     80 *
     81 */
     82typedef 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}
     89psIntArray;
     90
     91/** An array of floats.
     92 *
     93 * Struct for maintaining an array of floating point numbers.
     94 *
     95 */
     96typedef 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}
     103psFloatArray;
     104
     105/*****************************************************************************/
     106/* FUNCTION PROTOTYPES                                                       */
     107/*****************************************************************************/
     108
     109/** Allocate an integer array */
     110psIntArray *psIntArrayAlloc(
     111    int nalloc  ///< Total number of elements to make available
     112);
     113
     114/** Reallocate an integer array */
     115psIntArray *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 */
     122void 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 */
     131psFloatArray *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 */
     141psFloatArray *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 */
     152void 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 */
     161typedef 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}
     168psComplexArray;
     169
     170/** Constructor \ingroup DataGroup */
     171psComplexArray *psComplexArrayAlloc(int nalloc) ///< Total number of elements to make available
     172;
     173
     174/** Reallocator \ingroup DataGroup */
     175psComplexArray *psComplexArrayRealloc(psComplexArray *myArray, ///< Array to reallocate
     176                                      int nalloc) ///< Total number of elements to make available
     177;
     178
     179/** Destructor \ingroup DataGroup */
     180void psComplexArrayFree(psComplexArray *restrict myArray) ///< Array to free
     181;
     182
     183
     184/************************************************************************************************************/
     185
     186/** An array of double-precision real numbers */
     187typedef 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}
     194psDoubleArray;
     195
     196/** Constructor \ingroup DataGroup */
     197psDoubleArray *psDoubleArrayAlloc(int nalloc) ///< Total number of elements to make available
     198;
     199
     200/** Reallocator \ingroup DataGroup */
     201psDoubleArray *psDoubleArrayRealloc(psDoubleArray *myArray, ///< Array to reallocate
     202                                    int nalloc) ///< Total number of elements to make available
     203;
     204
     205/** Destructor \ingroup DataGroup */
     206void 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 */
     213typedef struct
     214{
     215    int n;    ///< Number of elements in use
     216    int nalloc;    ///< Number of total elements
     217    void **arr;    ///< The elements
     218}
     219psVoidPtrArray;
     220
     221/** Constructor \ingroup DataGroup */
     222psVoidPtrArray *psVoidPtrArrayAlloc(int nalloc) ///< Number of elements to use
     223;
     224
     225/** Reallocate \ingroup DataGroup */
     226psVoidPtrArray *psVoidPtrArrayRealloc(psVoidPtrArray *arr, ///< Array to reallocate
     227                                      int nalloc) ///< Number of elements
     228;
     229
     230/** Destructor \ingroup DataGroup */
     231void 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  
    1414 *  @author Ross Harman, MHPCC
    1515 *   
    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 $
    1818 *
    1919 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222/******************************************************************************/
    2323/*  INCLUDE FILES                                                             */
    24 /******************************************************************************/ 
     24/******************************************************************************/
    2525
    2626#include <stdio.h>
     
    7171 *  @return  int: Result of comparsion (-1, 0, or 1).
    7272 */
    73  
     73
    7474static int psCompare(
    7575    const void *x,  /**< First float to compare. */
     
    7979    float *item1 = NULL;
    8080    float *item2 = NULL;
    81    
     81
    8282    if(x == NULL || y == NULL) {
    8383        psError(__func__, " : Line %d - Null input argument: x=%d y=%d\n", __LINE__, x, y);
    8484    }
    85    
     85
    8686    item1 = (float*)x;
    8787    item2 = (float*)y;
    88    
     88
    8989    if(item1 == NULL || item2 == NULL) {
    9090        psError(__func__, " : Line %d - Improper cast to float: item1=%d item2=%d\n", __LINE__, item1, item2);
    9191    }
    92    
     92
    9393    if(*item1 < *item2) {
    9494        return -1;
    95     }
    96     else if(*item1 > *item2) {
     95    } else if(*item1 > *item2) {
    9796        return 1;
    98     }
    99     else {
     97    } else {
    10098        return 0;
    10199    }
     
    122120        return outArray;
    123121    }
    124    
     122
    125123    if(inArray == NULL) {
    126124        psError(__func__, " : Line %d - Null input array\n", __LINE__);
    127125        return outArray;
    128126    }
    129        
     127
    130128    // Initialize values
    131129    inN = inArray->n;
     
    134132    outArr = outArray->arr;
    135133    elSize = sizeof(float);
    136    
     134
    137135    if(inN != outN) {
    138136        psError(__func__, " : Line %d - Input and output array sizes are not equal: in=%d out=%d\n", __LINE__,
     
    140138        return outArray;
    141139    }
    142    
     140
    143141    // Copy input array values into output array
    144142    for(i=0; i<inN; i++) {
    145143        outArr[i] = inArr[i];
    146144    }
    147    
     145
    148146    // Sort output array
    149147    qsort((void*)outArr, inN, elSize, psCompare);
    150    
     148
    151149    return outArray;
    152150}
     
    166164    float diff = 0.0f;
    167165    psFloatArray *tmpFloatArray = NULL;
    168    
     166
    169167    if(outArray == NULL) {
    170168        psError(__func__, " : Line %d - Null output array\n", __LINE__);
    171169        return outArray;
    172170    }
    173    
     171
    174172    if(inArray == NULL) {
    175173        psError(__func__, " : Line %d - Null input array\n", __LINE__);
     
    189187    }
    190188
    191     tmpFloatArray = psFloatArrayAlloc(inN);
     189    tmpFloatArray = psFloatArrayAlloc(inN, inN);
    192190    tmpFloatArray = psSort(tmpFloatArray, inArray);
    193    
     191
    194192    for(i=0; i<inN; i++) {
    195193        tempVal = tmpFloatArray->arr[i];
     
    200198                break;
    201199            }
    202         } 
    203     }
    204    
     200        }
     201    }
     202
    205203    // Free temp memory
    206     psFreeFloatArray(tmpFloatArray);
    207    
    208     return outArray;   
     204    psFloatArrayFree(tmpFloatArray);
     205
     206    return outArray;
    209207}
  • 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 */
    215
     16/******************************************************************************/
     17/*  INCLUDE FILES                                                             */
     18/******************************************************************************/
     19#include "psMemory.h"
    320#include "psArray.h"
     21#include "psLogMsg.h"
    422
    5 #include <stdlib.h>
     23/******************************************************************************/
     24/*  DEFINE STATEMENTS                                                         */
     25/******************************************************************************/
    626
    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
     57psFloatArray* psFloatArrayAlloc(int nalloc)
    858{
    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;
    1472}
    1573
    16 int psFreeFloatArray(psFloatArray *inArray)
     74psFloatArray *psFloatArrayRealloc(psFloatArray *psArr, int nalloc)
    1775{
    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;
    2188}
    2289
    23 psIntArray *psIntArrayAlloc(int nalloc)
     90void psFloatArrayFree(psFloatArray *restrict psArr)
    2491{
    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__);
    3097}
     98
     99psIntArray* 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
     116psIntArray *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
     132void 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 */
     36typedef 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 */
     56typedef 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 */
     70typedef struct
     71{
     72    psElemType type;  ///< Primitive type.
     73    psDimen dimen;   ///< Dimensionality.
     74}
     75psType;
     76
     77/** An array of integers.
     78 *
     79 * Struct for maintaining an array of integer numbers.
     80 *
     81 */
     82typedef 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}
     89psIntArray;
     90
     91/** An array of floats.
     92 *
     93 * Struct for maintaining an array of floating point numbers.
     94 *
     95 */
     96typedef 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}
     103psFloatArray;
     104
     105/*****************************************************************************/
     106/* FUNCTION PROTOTYPES                                                       */
     107/*****************************************************************************/
     108
     109/** Allocate an integer array */
     110psIntArray *psIntArrayAlloc(
     111    int nalloc  ///< Total number of elements to make available
     112);
     113
     114/** Reallocate an integer array */
     115psIntArray *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 */
     122void 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 */
     131psFloatArray *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 */
     141psFloatArray *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 */
     152void 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 */
     161typedef 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}
     168psComplexArray;
     169
     170/** Constructor \ingroup DataGroup */
     171psComplexArray *psComplexArrayAlloc(int nalloc) ///< Total number of elements to make available
     172;
     173
     174/** Reallocator \ingroup DataGroup */
     175psComplexArray *psComplexArrayRealloc(psComplexArray *myArray, ///< Array to reallocate
     176                                      int nalloc) ///< Total number of elements to make available
     177;
     178
     179/** Destructor \ingroup DataGroup */
     180void psComplexArrayFree(psComplexArray *restrict myArray) ///< Array to free
     181;
     182
     183
     184/************************************************************************************************************/
     185
     186/** An array of double-precision real numbers */
     187typedef 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}
     194psDoubleArray;
     195
     196/** Constructor \ingroup DataGroup */
     197psDoubleArray *psDoubleArrayAlloc(int nalloc) ///< Total number of elements to make available
     198;
     199
     200/** Reallocator \ingroup DataGroup */
     201psDoubleArray *psDoubleArrayRealloc(psDoubleArray *myArray, ///< Array to reallocate
     202                                    int nalloc) ///< Total number of elements to make available
     203;
     204
     205/** Destructor \ingroup DataGroup */
     206void 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 */
     213typedef struct
     214{
     215    int n;    ///< Number of elements in use
     216    int nalloc;    ///< Number of total elements
     217    void **arr;    ///< The elements
     218}
     219psVoidPtrArray;
     220
     221/** Constructor \ingroup DataGroup */
     222psVoidPtrArray *psVoidPtrArrayAlloc(int nalloc) ///< Number of elements to use
     223;
     224
     225/** Reallocate \ingroup DataGroup */
     226psVoidPtrArray *psVoidPtrArrayRealloc(psVoidPtrArray *arr, ///< Array to reallocate
     227                                      int nalloc) ///< Number of elements
     228;
     229
     230/** Destructor \ingroup DataGroup */
     231void 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.