Changeset 9086
- Timestamp:
- Oct 1, 2006, 8:05:53 PM (20 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psList.c
r8627 r9086 6 6 * @author Robert Daniel DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.5 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2006- 08-26 04:34:28$8 * @version $Revision: 1.53 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-10-02 06:05:53 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 33 33 static void listFree(psList* list) 34 34 { 35 if (list == NULL) { 36 return; 37 } 38 39 // remove the associated iterators -- any references are invalid once psList is freed. 40 psArray* iterators = list->iterators; 41 // ONLY orphan the iterators if the list iterators are about to be destroyed 42 // a case where this is not the case is in psListSort. 43 if (psMemGetRefCounter(iterators) < 2) { 44 for (int i = 0; i < iterators->n; i++) { 45 // orphan iterators first to avoid any callbacks to dying list 46 ((psListIterator*)iterators->data[i])->list = NULL; 47 // remove all external references 48 psMemSetRefCounter(iterators->data[i], 1); 49 } 50 } 51 psFree(iterators); 35 if (list->iterators != NULL) { 36 37 // remove the associated iterators -- any references are invalid once psList is freed. 38 psArray* iterators = list->iterators; 39 // ONLY orphan the iterators if the list iterators are about to be destroyed 40 // a case where this is not the case is in psListSort. 41 if (psMemGetRefCounter(iterators) < 2) { 42 for (int i = 0; i < iterators->n; i++) { 43 // orphan iterators first to avoid any callbacks to dying list 44 ((psListIterator*)iterators->data[i])->list = NULL; 45 // remove all external references 46 psMemSetRefCounter(iterators->data[i], 1); 47 } 48 } 49 psFree(iterators); 50 } 52 51 53 52 for (psListElem* ptr = list->head; ptr != NULL;) { … … 63 62 static void listIteratorFree(psListIterator* iter) 64 63 { 65 if (iter == NULL) {66 return;67 }68 69 64 // remove this iterator from the parent list 70 65 if (iter->list != NULL) { … … 151 146 } 152 147 153 psListIterator* psListIteratorAlloc(psList* list, long location, bool mutable) 154 { 148 psListIterator* psListIteratorAlloc(psList* list, 149 long location, 150 bool mutable) 151 { 152 if (list == NULL) { 153 psError(PS_ERR_BAD_PARAMETER_NULL, true, 154 _("Specified list is NULL.")); 155 return false; 156 } 155 157 psListIterator* iter = psAlloc(sizeof(psListIterator)); 156 158 … … 180 182 long location) 181 183 { 182 if (iterator == NULL ) {184 if (iterator == NULL || iterator->list == NULL) { 183 185 return false; 184 186 } … … 214 216 int index = iterator->index; 215 217 if (cursor == NULL) { // set the cursor to the head if it is NULL 216 if (location > list->n/2) { // closer to tail or head? 217 cursor = list->tail; 218 index = list->n - 1; 219 } else { 220 cursor = list->head; 221 index = 0; 222 } 218 //XXX: if location can't be >= n, it def. can't be greater than n/2. 219 /* if (location > list->n/2) { // closer to tail or head? 220 cursor = list->tail; 221 index = list->n - 1; 222 } else { 223 */ 224 cursor = list->head; 225 index = 0; 226 // } 223 227 } 224 228 … … 243 247 } 244 248 245 bool psListAdd(psList* list, long location, psPtr data) 249 bool psListAdd(psList* list, 250 long location, 251 psPtr data) 246 252 { 247 253 … … 279 285 } 280 286 281 bool psListAddAfter(psListIterator* iterator, void* data) 287 bool psListAddAfter(psListIterator* iterator, 288 void* data) 282 289 { 283 290 if (data == NULL) { … … 332 339 list->n++; 333 340 334 if (cursor == list->tail) { 335 list->tail = elem; 336 } 337 341 //XXX: The following is unreachable. cursor can't == list->tail unless cursor->next == NULL. 342 // in which case list->tail will be set to elem. (list->tail = elem;) 343 /* if (cursor == list->tail) { 344 list->tail = elem; 345 } 346 */ 338 347 psArray* iterators = list->iterators; 339 348 int index = iterator->index; … … 348 357 } 349 358 350 bool psListAddBefore(psListIterator* iterator, void* data) 359 bool psListAddBefore(psListIterator* iterator, 360 void* data) 351 361 { 352 362 if (data == NULL) { … … 401 411 list->n++; 402 412 403 if (cursor == list->head) { 404 list->head = elem; 405 } 406 413 //XXX: The following is unreachable. cursor can't == list->head unless cursor->prev == NULL. 414 // in which case list->head will be set to elem. (list->tail = elem;) 415 /* if (cursor == list->head) { 416 list->head = elem; 417 } 418 */ 407 419 psArray* iterators = list->iterators; 408 420 int index = iterator->index; … … 469 481 } 470 482 471 psPtr psListGet(psList* list, long location) 483 psPtr psListGet(psList* list, 484 long location) 472 485 { 473 486 if (list == NULL) { … … 478 491 479 492 if (list->head == NULL) { // list empty? 493 psError(PS_ERR_BAD_PARAMETER_NULL, true, 494 _("Specified psList reference is empty.")); 480 495 return NULL; 481 496 } … … 527 542 } 528 543 if ((iterator->cursor == NULL) && (!iterator->offEnd)) { 529 psLogMsg(__func__,PS_LOG_WARN,"Attempt to get previous with itertator cursor NULL and offEnd false"); 544 psLogMsg(__func__,PS_LOG_WARN, 545 "Attempt to get previous element with NULL iterator cursor and offEnd=false"); 530 546 return NULL; 531 547 } … … 594 610 } 595 611 596 psList* psListSort(psList* list, psComparePtrFunc func) 612 psList* psListSort(psList* list, 613 psComparePtrFunc func) 597 614 { 598 615 psArray* arr; -
trunk/psLib/src/types/psList.h
r6505 r9086 7 7 * @ingroup LinkedList 8 8 * 9 * @version $Revision: 1.3 7$ $Name: not supported by cvs2svn $10 * @date $Date: 2006- 03-02 23:04:22$9 * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-10-02 06:05:53 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 139 139 ); 140 140 141 /** Adds a ndata item to a psList at position just before the list position given141 /** Adds a data item to a psList at position just before the list position given 142 142 * 143 143 * @return bool TRUE if item was successfully added, otherwise FALSE. 144 144 */ 145 145 bool psListAddBefore( 146 psListIterator* iterator, ///< list position to add item to146 psListIterator* iterator, ///< list position to add item to 147 147 psPtr data ///< data item to add. If NULL, list is not modified. 148 148 ); … … 154 154 bool psListRemove( 155 155 psList* list, ///< list to remove element from 156 long location ///< index of item156 long location ///< index of item 157 157 ); 158 158 … … 175 175 psPtr psListGet( 176 176 psList* list, ///< list to retrieve element from 177 long location ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL177 long location ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL 178 178 ); 179 179 … … 202 202 */ 203 203 psArray* psListToArray( 204 const psList* list ///< List to convert204 const psList* list ///< List to convert 205 205 ); 206 206 … … 211 211 */ 212 212 psList* psArrayToList( 213 const psArray* array ///< vector to convert213 const psArray* array ///< vector to convert 214 214 ); 215 215
Note:
See TracChangeset
for help on using the changeset viewer.
