Changeset 2793
- Timestamp:
- Dec 22, 2004, 3:14:52 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
collections/psArray.c (modified) (4 diffs)
-
collections/psArray.h (modified) (2 diffs)
-
types/psArray.c (modified) (4 diffs)
-
types/psArray.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psArray.c
r2384 r2793 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1. 19$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-1 1-19 00:33:39$11 * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-12-23 01:14:52 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 36 36 /*****************************************************************************/ 37 37 static void arrayFree(psArray* restrict psArr); 38 39 static void arrayFree(psArray* restrict psArr) 40 { 41 if (psArr == NULL) { 42 return; 43 } 44 45 psArrayElementFree(psArr); 46 47 psFree(psArr->data); 48 } 38 49 39 50 /*****************************************************************************/ … … 79 90 } 80 91 81 static void arrayFree(psArray* restrict psArr) 92 psArray* psArrayAdd(psArray* psArr, 93 int delta, 94 psPtr data) 82 95 { 83 96 if (psArr == NULL) { 84 return ;97 return psArr; 85 98 } 86 99 87 psArrayElementFree(psArr);100 int n = psArr->n; 88 101 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; 90 113 } 91 114 … … 95 118 psBool success = false; 96 119 97 if (psArr == NULL) {98 return success;99 }100 120 101 121 psS32 n = psArr->n; -
trunk/psLib/src/collections/psArray.h
r2204 r2793 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.1 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-1 0-27 00:57:31$14 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-12-23 01:14:52 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 68 68 psArray* psArrayRealloc( 69 69 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 */ 78 psArray* 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 71 83 ); 72 84 -
trunk/psLib/src/types/psArray.c
r2384 r2793 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1. 19$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-1 1-19 00:33:39$11 * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-12-23 01:14:52 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 36 36 /*****************************************************************************/ 37 37 static void arrayFree(psArray* restrict psArr); 38 39 static void arrayFree(psArray* restrict psArr) 40 { 41 if (psArr == NULL) { 42 return; 43 } 44 45 psArrayElementFree(psArr); 46 47 psFree(psArr->data); 48 } 38 49 39 50 /*****************************************************************************/ … … 79 90 } 80 91 81 static void arrayFree(psArray* restrict psArr) 92 psArray* psArrayAdd(psArray* psArr, 93 int delta, 94 psPtr data) 82 95 { 83 96 if (psArr == NULL) { 84 return ;97 return psArr; 85 98 } 86 99 87 psArrayElementFree(psArr);100 int n = psArr->n; 88 101 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; 90 113 } 91 114 … … 95 118 psBool success = false; 96 119 97 if (psArr == NULL) {98 return success;99 }100 120 101 121 psS32 n = psArr->n; -
trunk/psLib/src/types/psArray.h
r2204 r2793 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.1 8$ $Name: not supported by cvs2svn $15 * @date $Date: 2004-1 0-27 00:57:31$14 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2004-12-23 01:14:52 $ 16 16 * 17 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 68 68 psArray* psArrayRealloc( 69 69 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 */ 78 psArray* 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 71 83 ); 72 84
Note:
See TracChangeset
for help on using the changeset viewer.
