IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 22, 2004, 3:14:52 PM (22 years ago)
Author:
desonia
Message:

added psArrayAdd function.

File:
1 edited

Legend:

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

    r2384 r2793  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-11-19 00:33:39 $
     11 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-12-23 01:14:52 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636/*****************************************************************************/
    3737static void arrayFree(psArray* restrict psArr);
     38
     39static void arrayFree(psArray* restrict psArr)
     40{
     41    if (psArr == NULL) {
     42        return;
     43    }
     44
     45    psArrayElementFree(psArr);
     46
     47    psFree(psArr->data);
     48}
    3849
    3950/*****************************************************************************/
     
    7990}
    8091
    81 static void arrayFree(psArray* restrict psArr)
     92psArray* psArrayAdd(psArray* psArr,
     93                    int delta,
     94                    psPtr data)
    8295{
    8396    if (psArr == NULL) {
    84         return;
     97        return psArr;
    8598    }
    8699
    87     psArrayElementFree(psArr);
     100    int n = psArr->n;
    88101
    89     psFree(psArr->data);
     102    if (n >= psArr->nalloc) {
     103        // array needs to be expanded to make room for more elements
     104        int d = (delta > 0) ? delta : 10; // as spec'ed in SDRS.
     105        psArr = psArrayRealloc(psArr, n+d);
     106    }
     107
     108    // add the element to the end of the array.
     109    psArr->data[n] = data;
     110    psArr->n = n+1;
     111
     112    return psArr;
    90113}
    91114
     
    95118    psBool success = false;
    96119
    97     if (psArr == NULL) {
    98         return success;
    99     }
    100120
    101121    psS32 n = psArr->n;
Note: See TracChangeset for help on using the changeset viewer.