IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 10, 2005, 11:46:46 AM (21 years ago)
Author:
desonia
Message:

fixed bug in psPixels and tested psVectorExtend.

File:
1 edited

Legend:

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

    r3786 r4212  
    99*  @author Robert DeSonia, MHPCC
    1010*
    11 *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2005-04-29 02:25:09 $
     11*  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2005-06-10 21:46:46 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5454
    5555    elementSize = PSELEMTYPE_SIZEOF(elemType);
     56    if (elementSize < 1) {
     57        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     58                PS_ERRORTEXT_psVector_UNSUPPORTED_TYPE, elemType);
     59        return NULL;
     60    }
     61
    5662
    5763    // Create vector struct
     
    121127    in->n = n;
    122128    return in;
     129}
     130
     131psVector *psVectorExtend(psVector *vector, int delta, int nExtend)
     132{
     133    // can't handle a NULL vector (don't know the data type to allocate)
     134    if (vector == NULL) {
     135        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     136                PS_ERRORTEXT_psVector_NULL);
     137        return NULL;
     138    }
     139
     140    // requirement on delta; if < 1, set to 10.
     141    if (delta < 1) {
     142        delta = 10;
     143    }
     144
     145    // adjust the allocated size, if needed. (if nExtend < 1, this is will never happen)
     146    if (nExtend > 0) {
     147        unsigned int minAlloc = vector->n + nExtend + nExtend;
     148        if (vector->nalloc < minAlloc) {
     149            unsigned int nAlloc = delta + vector->nalloc;
     150            // make sure the delta is large enough hold twice the extended length.
     151            if (nAlloc < minAlloc) {
     152                nAlloc = minAlloc;
     153            }
     154            vector = psVectorRealloc(vector, nAlloc);
     155        }
     156    } else if (nExtend < -vector->n) {
     157        // For the case of a negative nExtend, need to check that we are not decreasing
     158        // vector beyond its own length (i.e., creating a negative length).
     159        nExtend = -vector->n;
     160    }
     161
     162    // increment the length by the value specified
     163    vector->n += nExtend;
     164
     165    return vector;
    123166}
    124167
Note: See TracChangeset for help on using the changeset viewer.