IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2793


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

added psArrayAdd function.

Location:
trunk/psLib/src
Files:
4 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;
  • trunk/psLib/src/collections/psArray.h

    r2204 r2793  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-10-27 00:57:31 $
     14 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-12-23 01:14:52 $
    1616 *
    1717 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6868psArray* psArrayRealloc(
    6969    psArray* restrict psArr,           ///< array to reallocate.
    70     psU32 nalloc                ///< Total number of elements to make available.
     70    psU32 nalloc                       ///< Total number of elements to make available.
     71);
     72
     73/** Add an element to the end the array, expanding the array storage if
     74 *  necessary.
     75 *
     76 *  @return psArray*        The array with the element added
     77 */
     78psArray* psArrayAdd(
     79    psArray* psArr,                    ///< array to operate on
     80    int delta,
     81    ///< the amount to expand array, if necessary.  If less than one, 10 will be used.
     82    psPtr data                         ///< the data pointer to add to psArray
    7183);
    7284
  • trunk/psLib/src/types/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;
  • trunk/psLib/src/types/psArray.h

    r2204 r2793  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-10-27 00:57:31 $
     14 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-12-23 01:14:52 $
    1616 *
    1717 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6868psArray* psArrayRealloc(
    6969    psArray* restrict psArr,           ///< array to reallocate.
    70     psU32 nalloc                ///< Total number of elements to make available.
     70    psU32 nalloc                       ///< Total number of elements to make available.
     71);
     72
     73/** Add an element to the end the array, expanding the array storage if
     74 *  necessary.
     75 *
     76 *  @return psArray*        The array with the element added
     77 */
     78psArray* psArrayAdd(
     79    psArray* psArr,                    ///< array to operate on
     80    int delta,
     81    ///< the amount to expand array, if necessary.  If less than one, 10 will be used.
     82    psPtr data                         ///< the data pointer to add to psArray
    7183);
    7284
Note: See TracChangeset for help on using the changeset viewer.