Changeset 1228
- Timestamp:
- Jul 15, 2004, 12:18:02 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 added
- 12 edited
-
collections/Makefile (modified) (2 diffs)
-
collections/psArray.c (added)
-
collections/psArray.h (added)
-
collections/psList.c (modified) (9 diffs)
-
collections/psList.d (modified) (1 diff)
-
collections/psList.h (modified) (4 diffs)
-
collections/psVector.c (modified) (4 diffs)
-
collections/psVector.h (modified) (3 diffs)
-
mathtypes/psVector.c (modified) (4 diffs)
-
mathtypes/psVector.h (modified) (3 diffs)
-
pslib.h (modified) (2 diffs)
-
sysUtils/psHash.d (modified) (1 diff)
-
types/psArray.c (added)
-
types/psArray.h (added)
-
types/psList.c (modified) (9 diffs)
-
types/psList.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/Makefile
r1205 r1228 3 3 ## Makefile: collections 4 4 ## 5 ## $Revision: 1.2 3$ $Name: not supported by cvs2svn $6 ## $Date: 2004-07- 09 21:48:07$5 ## $Revision: 1.24 $ $Name: not supported by cvs2svn $ 6 ## $Date: 2004-07-15 22:18:02 $ 7 7 ## 8 8 ## Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 36 36 psList.o \ 37 37 psScalar.o \ 38 psCompare.o 38 psCompare.o \ 39 psArray.o 39 40 40 41 # Define PHONY target "all" which will make all the necessary items -
trunk/psLib/src/collections/psList.c
r1193 r1228 6 6 * @author Robert Daniel DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-07- 08 01:05:00$8 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-07-15 22:18:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 401 401 * Convert a psList to/from a psVoidPtrArray 402 402 */ 403 ps Vector* psListToVector(psList* restrict list)403 psArray* psListToArray(psList* restrict list) 404 404 { 405 405 psListElem* ptr; 406 406 unsigned int n; 407 ps Vector* restrict arr;407 psArray* restrict arr; 408 408 409 409 if (list == NULL) { … … 412 412 413 413 if (list->size > 0) { 414 arr = ps VectorAlloc(list->size, PS_TYPE_PTR);415 } else { 416 arr = ps VectorAlloc(1, PS_TYPE_PTR);414 arr = psArrayAlloc(list->size); 415 } else { 416 arr = psArrayAlloc(1); 417 417 } 418 418 … … 422 422 n = list->size; 423 423 for (int i = 0; i < n; i++) { 424 arr->data .PTR[i] = psMemIncrRefCounter(ptr->data);424 arr->data[i] = psMemIncrRefCounter(ptr->data); 425 425 ptr = ptr->next; 426 426 } … … 429 429 } 430 430 431 psList* ps VectorToList(psVector* arr)431 psList* psArrayToList(psArray* arr) 432 432 { 433 433 unsigned int n; … … 435 435 436 436 if (arr == NULL) { 437 return NULL;438 }439 440 if (arr->type.type != PS_TYPE_PTR) {441 psError(__func__,"Can not convert a non pointer-vector to a linked list.");442 437 return NULL; 443 438 } … … 446 441 n = arr->n; 447 442 for (int i = 0; i < n; i++) { 448 psListAdd(list,arr->data .PTR[i],PS_LIST_TAIL);443 psListAdd(list,arr->data[i],PS_LIST_TAIL); 449 444 } 450 445 … … 455 450 psList* psListSort(psList* list, psComparePtrFcn compare) 456 451 { 457 ps Vector* vector;452 psArray* arr; 458 453 if (list == NULL) { 459 454 return NULL; … … 461 456 462 457 // convert to indexable vector for use by qsort. 463 vector = psListToVector(list);458 arr = psListToArray(list); 464 459 psFree(list); 465 460 466 qsort(vector->data.V, vector->n, sizeof(void*), 467 (int(*)(const void *, const void *))compare); 461 arr = psArraySort(arr,compare); 468 462 469 463 // convert back to linked list 470 list = ps VectorToList(vector);471 psFree( vector);464 list = psArrayToList(arr); 465 psFree(arr); 472 466 473 467 return list; -
trunk/psLib/src/collections/psList.d
r1111 r1228 1 1 psList.o psList.d : psList.c ../sysUtils/psError.h ../sysUtils/psAbort.h \ 2 ../sysUtils/psMemory.h psList.h psCompare.h ps Vector.h psType.h \2 ../sysUtils/psMemory.h psList.h psCompare.h psArray.h psType.h \ 3 3 ../sysUtils/psTrace.h ../sysUtils/psLogMsg.h -
trunk/psLib/src/collections/psList.h
r1193 r1228 10 10 * @ingroup LinkedList 11 11 * 12 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-07- 08 01:05:00$12 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-07-15 22:18:02 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 20 20 21 21 #include "psCompare.h" 22 #include "ps Vector.h"22 #include "psArray.h" 23 23 24 24 /** @addtogroup LinkedList … … 156 156 /** Convert a linked list to an array 157 157 * 158 * @return ps Vector* A new psVectorpopulated with elements from the list,158 * @return psArray* A new psArray populated with elements from the list, 159 159 * or NULL if the given dlist parameter is NULL. 160 160 */ 161 ps Vector* psListToVector(161 psArray* psListToArray( 162 162 psList *dlist ///< List to convert 163 163 ); … … 165 165 /** Convert array to a doubly-linked list 166 166 * 167 * @return psList* A new psList populated with elements formt the ps Vector,167 * @return psList* A new psList populated with elements formt the psArray, 168 168 * or NULL is the given arr parameter is NULL. 169 169 */ 170 psList* ps VectorToList(171 ps Vector* arr ///< vector to convert170 psList* psArrayToList( 171 psArray* arr ///< vector to convert 172 172 ); 173 173 -
trunk/psLib/src/collections/psVector.c
r1103 r1228 8 8 * @author Ross Harman, MHPCC 9 9 * 10 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-0 6-26 00:24:30$10 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-07-15 22:18:02 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 100 100 elementSize = PSELEMTYPE_SIZEOF(elemType); 101 101 if(nalloc < in->n) { 102 if (elemType == PS_TYPE_PTR) {103 for (int i = nalloc; i < in->n; i++) { // For reduction in vector size104 psMemDecrRefCounter(in->data.PTR[i]);105 }106 }107 102 in->n = nalloc; 108 103 } … … 139 134 140 135 141 // if vector of pointers, dereference old values.142 if (elemType == PS_TYPE_PTR) {143 for (int i = 0; i < in->n; i++) { // For reduction in vector size144 psMemDecrRefCounter(in->data.PTR[i]);145 in->data.PTR[i] = NULL;146 }147 }148 149 136 in->data.V = psRealloc(in->data.V,nalloc*PSELEMTYPE_SIZEOF(type)); 150 137 … … 162 149 } 163 150 164 if (psVec->type.type == PS_TYPE_PTR) {165 for(int i = 0; i < psVec->n; i++) {166 psFree(psVec->data.PTR[i]);167 psVec->data.PTR[i] = NULL;168 }169 }170 171 151 psFree(psVec->data.V); 172 152 } 173 174 void psVectorElementFree(psVector *restrict psVec)175 {176 177 if(psVec == NULL) {178 return;179 }180 181 if (psVec->type.type != PS_TYPE_PTR) {182 psLogMsg(__func__,PS_LOG_WARN,"psVectorElementFree only operates on void* vectors");183 return;184 }185 186 for(int i = 0; i < psVec->n; i++) {187 psFree(psVec->data.PTR[i]);188 psVec->data.PTR[i] = NULL;189 }190 }191 -
trunk/psLib/src/collections/psVector.h
r1073 r1228 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-0 6-23 23:00:15$13 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-07-15 22:18:02 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 49 49 psC32 *C32; ///< Single-precision complex data. 50 50 psC64 *C64; ///< Double-precision complex data. 51 psPTR *PTR; ///< Void pointers.52 51 psPTR V; ///< Pointer to data. 53 52 } data; ///< Union for data types. … … 100 99 ); 101 100 102 /** Deallocate/Dereference elements of a void pointer vector.103 *104 * Uses psLib memory allocation functions to deallocate/dereference elements of a vector of void pointers.105 * This function does not free the vector elements unless the user provides a elemFree function106 * pointer. If the elemFree function pointer is NULL, the reference cound of the elements are decremented107 * without being freed. The vector psVec is not freed, and its elements will all be set to NULL.108 *109 */110 void psVectorElementFree(111 psVector *restrict psVec ///< Void pointer vector to destroy.112 );113 114 101 /// @} 115 102 -
trunk/psLib/src/mathtypes/psVector.c
r1103 r1228 8 8 * @author Ross Harman, MHPCC 9 9 * 10 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-0 6-26 00:24:30$10 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-07-15 22:18:02 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 100 100 elementSize = PSELEMTYPE_SIZEOF(elemType); 101 101 if(nalloc < in->n) { 102 if (elemType == PS_TYPE_PTR) {103 for (int i = nalloc; i < in->n; i++) { // For reduction in vector size104 psMemDecrRefCounter(in->data.PTR[i]);105 }106 }107 102 in->n = nalloc; 108 103 } … … 139 134 140 135 141 // if vector of pointers, dereference old values.142 if (elemType == PS_TYPE_PTR) {143 for (int i = 0; i < in->n; i++) { // For reduction in vector size144 psMemDecrRefCounter(in->data.PTR[i]);145 in->data.PTR[i] = NULL;146 }147 }148 149 136 in->data.V = psRealloc(in->data.V,nalloc*PSELEMTYPE_SIZEOF(type)); 150 137 … … 162 149 } 163 150 164 if (psVec->type.type == PS_TYPE_PTR) {165 for(int i = 0; i < psVec->n; i++) {166 psFree(psVec->data.PTR[i]);167 psVec->data.PTR[i] = NULL;168 }169 }170 171 151 psFree(psVec->data.V); 172 152 } 173 174 void psVectorElementFree(psVector *restrict psVec)175 {176 177 if(psVec == NULL) {178 return;179 }180 181 if (psVec->type.type != PS_TYPE_PTR) {182 psLogMsg(__func__,PS_LOG_WARN,"psVectorElementFree only operates on void* vectors");183 return;184 }185 186 for(int i = 0; i < psVec->n; i++) {187 psFree(psVec->data.PTR[i]);188 psVec->data.PTR[i] = NULL;189 }190 }191 -
trunk/psLib/src/mathtypes/psVector.h
r1073 r1228 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-0 6-23 23:00:15$13 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-07-15 22:18:02 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 49 49 psC32 *C32; ///< Single-precision complex data. 50 50 psC64 *C64; ///< Double-precision complex data. 51 psPTR *PTR; ///< Void pointers.52 51 psPTR V; ///< Pointer to data. 53 52 } data; ///< Union for data types. … … 100 99 ); 101 100 102 /** Deallocate/Dereference elements of a void pointer vector.103 *104 * Uses psLib memory allocation functions to deallocate/dereference elements of a vector of void pointers.105 * This function does not free the vector elements unless the user provides a elemFree function106 * pointer. If the elemFree function pointer is NULL, the reference cound of the elements are decremented107 * without being freed. The vector psVec is not freed, and its elements will all be set to NULL.108 *109 */110 void psVectorElementFree(111 psVector *restrict psVec ///< Void pointer vector to destroy.112 );113 114 101 /// @} 115 102 -
trunk/psLib/src/pslib.h
r1222 r1228 8 8 * @author Eric Van Alst, MHPCC 9 9 * 10 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-07-15 19:01:28$10 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-07-15 22:18:02 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 73 73 #include "psVector.h" 74 74 75 #include "psArray.h" 76 75 77 /// @defgroup Image Image Container 76 78 /// @ingroup DataContainer -
trunk/psLib/src/sysUtils/psHash.d
r1111 r1228 1 1 psHash.o psHash.d : psHash.c psHash.h ../collections/psList.h \ 2 ../collections/psCompare.h ../collections/ps Vector.h \2 ../collections/psCompare.h ../collections/psArray.h \ 3 3 ../collections/psType.h psMemory.h psString.h psTrace.h psAbort.h -
trunk/psLib/src/types/psList.c
r1193 r1228 6 6 * @author Robert Daniel DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-07- 08 01:05:00$8 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-07-15 22:18:02 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 401 401 * Convert a psList to/from a psVoidPtrArray 402 402 */ 403 ps Vector* psListToVector(psList* restrict list)403 psArray* psListToArray(psList* restrict list) 404 404 { 405 405 psListElem* ptr; 406 406 unsigned int n; 407 ps Vector* restrict arr;407 psArray* restrict arr; 408 408 409 409 if (list == NULL) { … … 412 412 413 413 if (list->size > 0) { 414 arr = ps VectorAlloc(list->size, PS_TYPE_PTR);415 } else { 416 arr = ps VectorAlloc(1, PS_TYPE_PTR);414 arr = psArrayAlloc(list->size); 415 } else { 416 arr = psArrayAlloc(1); 417 417 } 418 418 … … 422 422 n = list->size; 423 423 for (int i = 0; i < n; i++) { 424 arr->data .PTR[i] = psMemIncrRefCounter(ptr->data);424 arr->data[i] = psMemIncrRefCounter(ptr->data); 425 425 ptr = ptr->next; 426 426 } … … 429 429 } 430 430 431 psList* ps VectorToList(psVector* arr)431 psList* psArrayToList(psArray* arr) 432 432 { 433 433 unsigned int n; … … 435 435 436 436 if (arr == NULL) { 437 return NULL;438 }439 440 if (arr->type.type != PS_TYPE_PTR) {441 psError(__func__,"Can not convert a non pointer-vector to a linked list.");442 437 return NULL; 443 438 } … … 446 441 n = arr->n; 447 442 for (int i = 0; i < n; i++) { 448 psListAdd(list,arr->data .PTR[i],PS_LIST_TAIL);443 psListAdd(list,arr->data[i],PS_LIST_TAIL); 449 444 } 450 445 … … 455 450 psList* psListSort(psList* list, psComparePtrFcn compare) 456 451 { 457 ps Vector* vector;452 psArray* arr; 458 453 if (list == NULL) { 459 454 return NULL; … … 461 456 462 457 // convert to indexable vector for use by qsort. 463 vector = psListToVector(list);458 arr = psListToArray(list); 464 459 psFree(list); 465 460 466 qsort(vector->data.V, vector->n, sizeof(void*), 467 (int(*)(const void *, const void *))compare); 461 arr = psArraySort(arr,compare); 468 462 469 463 // convert back to linked list 470 list = ps VectorToList(vector);471 psFree( vector);464 list = psArrayToList(arr); 465 psFree(arr); 472 466 473 467 return list; -
trunk/psLib/src/types/psList.h
r1193 r1228 10 10 * @ingroup LinkedList 11 11 * 12 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-07- 08 01:05:00$12 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-07-15 22:18:02 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 20 20 21 21 #include "psCompare.h" 22 #include "ps Vector.h"22 #include "psArray.h" 23 23 24 24 /** @addtogroup LinkedList … … 156 156 /** Convert a linked list to an array 157 157 * 158 * @return ps Vector* A new psVectorpopulated with elements from the list,158 * @return psArray* A new psArray populated with elements from the list, 159 159 * or NULL if the given dlist parameter is NULL. 160 160 */ 161 ps Vector* psListToVector(161 psArray* psListToArray( 162 162 psList *dlist ///< List to convert 163 163 ); … … 165 165 /** Convert array to a doubly-linked list 166 166 * 167 * @return psList* A new psList populated with elements formt the ps Vector,167 * @return psList* A new psList populated with elements formt the psArray, 168 168 * or NULL is the given arr parameter is NULL. 169 169 */ 170 psList* ps VectorToList(171 ps Vector* arr ///< vector to convert170 psList* psArrayToList( 171 psArray* arr ///< vector to convert 172 172 ); 173 173
Note:
See TracChangeset
for help on using the changeset viewer.
