IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 28, 2005, 10:17:52 AM (21 years ago)
Author:
drobbin
Message:

updated files in accordance with requested revisions in apidelta-report-cycle6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psVector.c

    r4392 r4409  
    99*  @author Robert DeSonia, MHPCC
    1010*
    11 *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2005-06-25 02:02:05 $
     11*  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2005-06-28 20:17:52 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4848// FUNCTION IMPLEMENTATION - PUBLIC
    4949
    50 psVector* psVectorAlloc(psU32 nalloc, psElemType elemType)
     50psVector* psVectorAlloc(unsigned long nalloc, psElemType type)
    5151{
    5252    psVector* psVec = NULL;
    5353    psS32 elementSize = 0;
    5454
    55     elementSize = PSELEMTYPE_SIZEOF(elemType);
     55    elementSize = PSELEMTYPE_SIZEOF(type);
    5656    if (elementSize < 1) {
    5757        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    58                 PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE, elemType);
     58                PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE, type);
    5959        return NULL;
    6060    }
     
    6666
    6767    psVec->type.dimen = PS_DIMEN_VECTOR;
    68     psVec->type.type = elemType;
     68    psVec->type.type = type;
    6969    *(int*)&psVec->nalloc = nalloc;
    7070    psVec->n = nalloc;
     
    7676}
    7777
    78 psVector* psVectorRealloc(psVector* in, psU32 nalloc)
     78psVector* psVectorRealloc(psVector* vector, unsigned long nalloc)
    7979{
    8080    psS32 elementSize = 0;
    8181    psElemType elemType;
    8282
    83     if (in == NULL) {
     83    if (vector == NULL) {
    8484        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    8585                PS_ERRORTEXT_psVector_REALLOC_NULL);
    8686        return NULL;
    87     } else if (in->nalloc != nalloc) {     // No need to realloc to same size
    88         elemType = in->type.type;
     87    } else if (vector->nalloc != nalloc) {     // No need to realloc to same size
     88        elemType = vector->type.type;
    8989        elementSize = PSELEMTYPE_SIZEOF(elemType);
    90         if (nalloc < in->n) {
    91             in->n = nalloc;
     90        if (nalloc < vector->n) {
     91            vector->n = nalloc;
    9292        }
    9393        // Realloc after decrementation to avoid accessing freed array elements
    94         in->data.U8 = psRealloc(in->data.U8, nalloc * elementSize);
    95         *(int*)&in->nalloc = nalloc;
    96     }
    97 
    98     return in;
    99 }
    100 
    101 psVector* psVectorRecycle(psVector* in, psU32 n, psElemType type)
     94        vector->data.U8 = psRealloc(vector->data.U8, nalloc * elementSize);
     95        *(int*)&vector->nalloc = nalloc;
     96    }
     97
     98    return vector;
     99}
     100
     101psVector* psVectorRecycle(psVector* vector, unsigned long nalloc, psElemType type)
    102102{
    103103    psS32 byteSize;
    104104
    105     if (in == NULL) {
    106         return psVectorAlloc(n, type);
    107     }
    108 
    109     if (in->type.dimen !=  PS_DIMEN_VECTOR &&
    110             in->type.dimen !=  PS_DIMEN_TRANSV) {
    111         psFree(in);
     105    if (vector == NULL) {
     106        return psVectorAlloc(nalloc, type);
     107    }
     108
     109    if (vector->type.dimen !=  PS_DIMEN_VECTOR &&
     110            vector->type.dimen !=  PS_DIMEN_TRANSV) {
     111        psFree(vector);
    112112        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    113113                PS_ERRORTEXT_psVector_NOT_A_VECTOR);
     
    115115    }
    116116
    117     byteSize = n * PSELEMTYPE_SIZEOF(type);
     117    byteSize = nalloc * PSELEMTYPE_SIZEOF(type);
    118118
    119119    // need to increase data buffer?
    120     if (byteSize > in->nalloc*PSELEMTYPE_SIZEOF(in->type.type)) {
    121         in->data.U8 = psRealloc(in->data.U8, byteSize);
    122         *(int*)&in->nalloc = n;
    123     }
    124 
    125     in->type.dimen = PS_DIMEN_VECTOR;
    126     in->type.type = type;
    127     in->n = n;
    128     return in;
     120    if (byteSize > vector->nalloc*PSELEMTYPE_SIZEOF(vector->type.type)) {
     121        vector->data.U8 = psRealloc(vector->data.U8, byteSize);
     122        *(int*)&vector->nalloc = nalloc;
     123    }
     124
     125    vector->type.dimen = PS_DIMEN_VECTOR;
     126    vector->type.type = type;
     127    vector->n = nalloc;
     128    return vector;
    129129}
    130130
Note: See TracChangeset for help on using the changeset viewer.