IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14905


Ignore:
Timestamp:
Sep 20, 2007, 9:15:42 AM (19 years ago)
Author:
magnier
Message:

created function psArrayRemoveDataNoFree

Location:
branches/eam_branch_20070830/psLib/src/types
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070830/psLib/src/types/psArray.c

    r12289 r14905  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.61 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2007-03-07 02:50:15 $
     11 *  @version $Revision: 1.61.8.1 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2007-09-20 19:15:42 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    163163}
    164164
     165// drop an item from the array and free it
    165166bool psArrayRemoveData(psArray* array,
    166167                       const psPtr data)
     
    185186}
    186187
     188// drop an item from the array and do not free it: this
     189// can be useful in the free function of a data type
     190// with a reference on another structure
     191bool psArrayRemoveDataNoFree(psArray* array,
     192                             const psPtr data)
     193{
     194    PS_ASSERT_ARRAY_NON_NULL(array, false);
     195    PS_ASSERT_PTR_NON_NULL(data, false);
     196
     197    bool success = false;
     198    long n = array->n;
     199    psPtr *arrayData = array->data;
     200    for (long i = n-1; i >= 0; i--) {
     201        if (arrayData[i] == data) {
     202            memmove(&arrayData[i],&arrayData[i+1],(n-i-1)*sizeof(psPtr));
     203            n--;
     204            success = true;
     205        }
     206    }
     207    array->n = n; // reset the array size to indicate the removed item(s)
     208
     209    return success;
     210}
     211
    187212bool psArrayRemoveIndex(psArray* array,
    188213                        long index)
  • branches/eam_branch_20070830/psLib/src/types/psArray.h

    r14452 r14905  
    1010 *  @author Joshua Hoblitt, University of Hawaii
    1111 *
    12  *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2007-08-09 01:40:08 $
     12 *  @version $Revision: 1.49.2.1 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2007-09-20 19:15:42 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    161161
    162162
     163/** Remove an element from the array by it's pointer WITHOUT freeing
     164 *
     165 *  Finds and removes the specified data pointer from the list, but does not free it
     166 *
     167 * @return bool:  TRUE if the specified data pointer was found and removed,
     168 *                otherwise FALSE.
     169 *
     170 */
     171bool psArrayRemoveDataNoFree(
     172    psArray* array,                    ///< array to operate on
     173    const psPtr data                   ///< the data pointer to remove from psArray
     174);
     175
     176
    163177/** Remove an element from the array
    164178 *
Note: See TracChangeset for help on using the changeset viewer.