Changeset 2698 for trunk/psLib/src/collections/psList.c
- Timestamp:
- Dec 10, 2004, 3:19:06 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psList.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psList.c
r2694 r2698 6 6 * @author Robert Daniel DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-12-1 0 21:43:16 $8 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-12-11 01:19:06 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 41 41 pthread_mutex_lock(&list->lock) 42 42 ; 43 44 // remove the free function of iterators to avoid double removal from list 45 psArray* iterators = list->iterators; 46 for (int i = 0; i < iterators->n; i++) { 47 p_psMemSetDeallocator(iterators->data[i], NULL); 48 } 43 49 44 50 psFree(list->iterators); … … 128 134 list->head = list->tail = NULL; 129 135 list->iterators = psArrayAlloc(16); 136 list->iterators->n = 0; 130 137 131 138 // create a default iterator 132 list->iterators->data[0] = psListIteratorAlloc(list,PS_LIST_HEAD); 133 list->iterators->n = 1; 139 psListIteratorAlloc(list,PS_LIST_HEAD); 134 140 135 141 pthread_mutex_init(&(list->lock), NULL) … … 183 189 psList* list = iterator->list; 184 190 185 if (location >= (int)list->size) {186 psLogMsg(__func__, PS_LOG_WARN,187 "Specified index, %d, is beyond the end of the psList, which "188 "has only %d elements. Assuming tail.",189 location, list->size);190 location = PS_LIST_TAIL;191 }192 193 191 if (location == PS_LIST_TAIL) { 194 192 iterator->cursor = list->tail; … … 198 196 } 199 197 200 if (location <= 0) { // Invalid index 201 return false; 202 } 203 198 if (location == PS_LIST_HEAD) { 199 iterator->cursor = list->head; 200 iterator->index = 0; 201 iterator->offEnd = false; 202 return true; 203 } 204 205 if (location < 0 || location >= (int)list->size) { 206 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 207 PS_ERRORTEXT_psList_LOCATION_INVALID, 208 location); 209 return false; 210 } 204 211 205 212 psListElem* cursor = iterator->cursor; … … 250 257 } 251 258 259 if (location >= (int)list->size) { 260 psLogMsg(__func__,PS_LOG_WARN, 261 "Specified location, %d, is beyond the end of the list. " 262 "Adding data item to tail.", 263 location); 264 location = PS_LIST_TAIL; 265 } 266 252 267 // move ourselves to the given position 253 if (list->iterators->n < 1 || 254 ! psListIteratorSet(list->iterators->data[0],location)) { 255 // oh no, I can't find where to add this! 256 psError(PS_ERR_UNKNOWN, false, 257 PS_ERRORTEXT_psList_LOCATION_INVALID, 258 location); 268 if (! psListIteratorSet(list->iterators->data[0],location)) { 259 269 return false; 260 270 } … … 308 318 if (elem->next == NULL) { 309 319 list->tail = elem; 320 } else { 321 elem->next->prev = elem; 310 322 } 311 323 } … … 374 386 if (elem->prev == NULL) { 375 387 list->head = elem; 388 } else { 389 elem->prev->next = elem; 376 390 } 377 391 } … … 411 425 // move ourselves to the given position 412 426 psListIterator* defaultIterator = list->iterators->data[0]; 413 if (list->iterators->n < 1 || 414 ! psListIteratorSet(defaultIterator,location)) { 415 // oh no, I can't find where to add this! 416 psError(PS_ERR_UNKNOWN, false, 417 PS_ERRORTEXT_psList_LOCATION_INVALID, 418 location); 427 if (! psListIteratorSet(defaultIterator,location)) { 419 428 return false; 420 429 } … … 438 447 } 439 448 440 psListIterator* iterator = list->iterators->data[0]; 441 psListIteratorSet(iterator,PS_LIST_HEAD); 442 443 psPtr iteratorData = psListGetNext(iterator); 444 while (iteratorData != NULL && iteratorData != data) { 445 iteratorData = psListGetNext(iterator); 446 } 447 448 if (iteratorData == NULL) { 449 psListElem* elem = list->head; 450 int index = 0; 451 while (elem != NULL && elem->data != data) { 452 elem = elem->next; 453 index++; 454 } 455 if (elem == NULL) { 449 456 psError(PS_ERR_BAD_PARAMETER_NULL, true, 450 457 PS_ERRORTEXT_psList_DATA_NOT_FOUND); … … 452 459 } 453 460 461 psListIterator* iterator = (psListIterator*)list->iterators->data[0]; 462 iterator->index = index; 463 iterator->cursor = elem; 464 454 465 return listIteratorRemove(iterator); 455 466 } … … 460 471 psError(PS_ERR_BAD_PARAMETER_NULL, true, 461 472 PS_ERRORTEXT_psList_LIST_NULL); 462 return false; 473 return NULL; 474 } 475 476 if (list->head == NULL) { // list empty? 477 return NULL; 463 478 } 464 479
Note:
See TracChangeset
for help on using the changeset viewer.
