IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9730 for trunk/psLib/src/types


Ignore:
Timestamp:
Oct 24, 2006, 12:55:05 PM (20 years ago)
Author:
Paul Price
Message:

Following today's meeting, we agreed that psVectorAlloc (and therefore
psArrayAlloc also) shall set the number of elements in use to equal the
number of elements allocated. We introduce new functions,
psVectorAllocEmpty and psArrayAllocEmpty, that allocate a vector and set
the length to zero.

Location:
trunk/psLib/src/types
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psArray.c

    r9543 r9730  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2006-10-13 22:24:29 $
     11 *  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2006-10-24 22:52:56 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4949}
    5050
     51// Allocate an array, deliberately leave size unset.
     52static psArray *arrayAlloc(long nalloc)
     53{
     54    if (nalloc < 0) {
     55        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     56                "Can't allocate a psArray of negative size.");
     57        return NULL;
     58    }
     59
     60    // Create vector struct
     61    psArray *array = (psArray*)psAlloc(sizeof(psArray));
     62    psMemSetDeallocator(array, (psFreeFunc)arrayFree);
     63
     64    P_PSARRAY_SET_NALLOC(array, nalloc);
     65    // Create vector data array
     66    array->data = psAlloc(nalloc * sizeof(psPtr));
     67    memset(array->data, 0, sizeof(void*) * nalloc);  //set the initial values of data to NULL
     68
     69    return array;
     70}
    5171
    5272/*****************************************************************************
     
    5575psArray* psArrayAlloc(long nalloc)
    5676{
    57     if (nalloc < 0) {
    58         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    59                 "Can't allocate a psArray of negative size.");
    60         return NULL;
    61     }
    62     psArray* psArr = NULL;
    63 
    64     // Create vector struct
    65     psArr = (psArray* ) psAlloc(sizeof(psArray));
    66     psMemSetDeallocator(psArr, (psFreeFunc) arrayFree);
    67 
    68     P_PSARRAY_SET_NALLOC(psArr,nalloc);
    69     psArr->n = 0;  //set the initial number of elements in use to 0
    70     // Create vector data array
    71     psArr->data = psAlloc(nalloc * sizeof(psPtr));
    72     memset(psArr->data, 0, sizeof(void*) * nalloc);  //set the initial values of data to NULL
    73 
    74     return psArr;
     77    psArray *array = arrayAlloc(nalloc);
     78    if (!array) {
     79        return NULL;
     80    }
     81    array->n = nalloc;
     82    return array;
     83}
     84
     85psArray* psArrayAllocEmpty(long nalloc)
     86{
     87    psArray *array = arrayAlloc(nalloc);
     88    if (!array) {
     89        return NULL;
     90    }
     91    array->n = 0;
     92    return array;
    7593}
    7694
  • trunk/psLib/src/types/psArray.h

    r9543 r9730  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2006-10-13 22:24:29 $
     13 *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2006-10-24 22:52:56 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6060
    6161
    62 /** Allocate an array.
     62/** Allocate an array, set the length to the number of allocated elements
    6363 *
    6464 * Uses psLib memory allocation functions to create an array collection of
     
    6969 */
    7070psArray* psArrayAlloc(
     71    long nalloc                        ///< Total number of elements to make available.
     72);
     73
     74/** Allocate an array, set the length to zero.
     75 *
     76 * Uses psLib memory allocation functions to create an array collection of
     77 * data
     78 *
     79 * @return psArray* : Pointer to psArray.
     80 *
     81 */
     82psArray* psArrayAllocEmpty(
    7183    long nalloc                        ///< Total number of elements to make available.
    7284);
  • trunk/psLib/src/types/psHash.c

    r9538 r9730  
    1212*  @author GLG, MHPCC
    1313*
    14 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2006-10-13 21:13:48 $
     14*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2006-10-24 22:52:56 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    433433
    434434    psArray* result = psArrayAlloc(nElements);
    435     result->n = nElements;
    436435
    437436    // now fill in the array with the hash hash's data
  • trunk/psLib/src/types/psList.c

    r9538 r9730  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-10-13 21:13:48 $
     8 *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-10-24 22:52:56 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2525#define ITER_INIT_HEAD ((psPtr )1)         // next iteration should return head
    2626#define ITER_INIT_TAIL ((psPtr )2)         // next iteration should return tail
     27
     28#define INITIAL_NUM_ITERATORS 16        // Initial number of iterators to create
    2729
    2830// private functions.
     
    125127    list->n = 0;
    126128    list->head = list->tail = NULL;
    127     list->iterators = psArrayAlloc(16);
    128     list->iterators->n = 0;
     129    list->iterators = psArrayAllocEmpty(INITIAL_NUM_ITERATORS);
    129130
    130131    // create a default iterator
     
    564565psArray* psListToArray(const psList* list)
    565566{
    566     psListElem* ptr;
    567     psU32 n;
    568     psArray* arr;
    569 
    570     if (list == NULL) {
    571         return NULL;
    572     }
    573 
    574     //XXX: Following is unnecessary as a list->n = 0 should do ArrayAlloc(0) I believe.
    575     /*    if (list->n > 0) {
    576             arr = psArrayAlloc(list->n);
    577         } else {
    578             arr = psArrayAlloc(1);
    579         }
    580     */
    581     arr = psArrayAlloc(list->n);
    582     arr->n = list->n;
    583 
    584     ptr = list->head;
    585     n = list->n;
     567    PS_ASSERT_PTR_NON_NULL(list, NULL);
     568
     569    long n = list->n;
     570    psArray *arr = psArrayAlloc(n);
     571
     572    psListElem *ptr = list->head;
    586573    for (psS32 i = 0; i < n; i++) {
    587574        arr->data[i] = psMemIncrRefCounter(ptr->data);
  • trunk/psLib/src/types/psLookupTable.c

    r9715 r9730  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-10-22 00:51:05 $
     9*  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-10-24 22:52:56 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    3636#define MAX_STRING_LENGTH   256
    3737#define ARRAY_STRIDE        16
    38 
     38#define INITIAL_NUM         10          // Initial number of elements
    3939/******************************************************************************/
    4040/*  TYPE DEFINITIONS                                                          */
     
    449449
    450450    // Create output array and set array elements to zero
    451     outputArray = psArrayAlloc(10);
    452     outputArray->n = 0;
     451    outputArray = psArrayAllocEmpty(INITIAL_NUM);
    453452
    454453    // Parse the format string to determine how many vectors
     
    629628    // Check if array is sorted on the index column
    630629    psVector* sortedIndex = psVectorAlloc(numRows,PS_TYPE_U32);
    631     sortedIndex->n = numRows;
    632630    sortedIndex = psVectorSortIndex(sortedIndex,indexColumnVector);
    633631    for(psS32 i = 0; i < numRows; i++ ) {
     
    645643            psS32 type = ((psVector*)(vectors->data[j]))->type.type;
    646644            newValueArray->data[j] = psVectorAlloc(numRows,type);
    647             ((psVector*)(newValueArray->data[j]))->n = numRows;
    648             newValueArray->n++;
    649645        }
    650646
  • trunk/psLib/src/types/psMetadataConfig.c

    r9720 r9730  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.95 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-10-24 01:15:47 $
     12*  @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-10-24 22:52:56 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4747/** Maximum size of a string */
    4848#define MAX_STRING_LENGTH 1024
     49#define INITIAL_LENGTH 10               // Initial length for arrays
    4950
    5051/******************************************************************************/
     
    7374static psMetadata* setMetadataItem(psMetadata* template, char* linePtr)
    7475;
    75 static void parseLevelInfoFree(p_psParseLevelInfo* info);
    76 static psBool parseLine(psS32* level,   psArray* levelArray, char*  linePtr, psS32 lineCount, psBool overwrite);
    77 static psBool parseMetadataItem(char* keyName, psS32* level, psArray* levelArray, char* linePtr, psS32 lineCount, psMetadataFlags flags);
     76static psBool parseLine(psS32* level,   psArray* levelArray, char*  linePtr,
     77                        psS32 lineCount, psBool overwrite);
     78static psBool parseMetadataItem(char* keyName, psS32* level, psArray* levelArray,
     79                                char* linePtr, psS32 lineCount, psMetadataFlags flags);
    7880static psString formatMetadataItem(psMetadataItem *item);
    7981static psArray *p_psMetadataKeyArray(psMetadata *md);
     82
     83
     84// A metadata data structure used in parsing arrays.
     85// Contains array information and the metadata storage location.
     86typedef struct
     87{
     88    psArray*    nonUniqueKeyArray;     ///< non-unique key names
     89    psArray*    typeArray;             ///< array of user defined types
     90    psArray*    templateArray;         ///< array of user type templates
     91    psMetadata* metadata;              ///< metadata container
     92    char*       name;                  ///< name of key
     93}
     94p_psParseLevelInfo;
     95
    8096static void parseLevelInfoFree(p_psParseLevelInfo* info)
    8197{
     
    85101    psFree(info->name);
    86102    psFree(info->metadata);
     103}
     104
     105static p_psParseLevelInfo* p_psParseLevelInfoAlloc(void)
     106{
     107    // Allocate memory for parse level info
     108    p_psParseLevelInfo *info = (p_psParseLevelInfo*)psAlloc(sizeof(p_psParseLevelInfo));
     109    psMemSetDeallocator(info,(psFreeFunc)parseLevelInfoFree);
     110
     111    info->nonUniqueKeyArray = psArrayAllocEmpty(INITIAL_LENGTH);
     112    info->typeArray = psArrayAllocEmpty(INITIAL_LENGTH);
     113    info->templateArray = psArrayAllocEmpty(INITIAL_LENGTH);
     114    info->metadata = NULL;
     115    info->name = NULL;
     116
     117    return info;
    87118}
    88119
     
    350381        inString = saveValue;
    351382        end = NULL;
    352         vec = psVectorAlloc(numValues, elemType);
     383        vec = psVectorAllocEmpty(numValues, elemType);
    353384
    354385        while(*inString!='\0') {
     
    406437}
    407438
     439
    408440/*****************************************************************************/
    409441/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
    410442/*****************************************************************************/
    411 
    412 p_psParseLevelInfo* p_psParseLevelInfoAlloc(void)
    413 {
    414 
    415     p_psParseLevelInfo* info = NULL;
    416 
    417     // Allocate memory for parse level info
    418     info = (p_psParseLevelInfo*)psAlloc(sizeof(p_psParseLevelInfo));
    419 
    420     // If allocation successful then initialize members
    421     if(info != NULL) {
    422 
    423         info->nonUniqueKeyArray = psArrayAlloc(10);
    424 
    425         info->typeArray = psArrayAlloc(10);
    426 
    427         info->templateArray = psArrayAlloc(10);
    428 
    429         info->metadata = NULL;
    430         info->name = NULL;
    431 
    432         // Set memory deallocator
    433         psMemSetDeallocator(info,(psFreeFunc)parseLevelInfoFree);
    434     }
    435     return info;
    436 }
    437443
    438444bool psMetadataItemPrint(FILE * fd,
     
    12201226
    12211227    // Allocate array to store parse level information
    1222     parseLevelInfoArray = psArrayAlloc(10);
     1228    parseLevelInfoArray = psArrayAllocEmpty(INITIAL_LENGTH);
    12231229
    12241230    // Set parse level info for the top level
     
    15221528    PS_ASSERT_PTR_NON_NULL(md, NULL);
    15231529
    1524     psArray *keys = psArrayAlloc(psListLength(md->list));
     1530    psArray *keys = psArrayAllocEmpty(psListLength(md->list));
    15251531
    15261532    // since we want to preserve the order of the keys in the metadata we can't
  • trunk/psLib/src/types/psMetadataConfig.h

    r9720 r9730  
    1010 *  @author Robert DeSonia, MHPCC
    1111 *
    12  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-10-24 01:15:47 $
     12 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-10-24 22:52:56 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2222/// @addtogroup Metadata
    2323/// @{
    24 
    25 /** A metadata data structure used in parsing arrays.
    26  *
    27  *  Contains array information and the metadata storage location.
    28 */
    29 typedef struct
    30 {
    31     psArray*    nonUniqueKeyArray;     ///< non-unique key names
    32     psArray*    typeArray;             ///< array of user defined types
    33     psArray*    templateArray;         ///< array of user type templates
    34     psMetadata* metadata;              ///< metadata container
    35     char*       name;                  ///< name of key
    36 }
    37 p_psParseLevelInfo;
    38 
    39 /** Allocates a p_psParseLevelInfo structure
    40  *
    41  *  @return p_psParseLevelInfo* :   new p_psParseLevelInfo struct
    42  */
    43 p_psParseLevelInfo* p_psParseLevelInfoAlloc(void);
    4424
    4525/** Print metadata item to file.
Note: See TracChangeset for help on using the changeset viewer.