Changeset 1747 for trunk/psLib/src/collections/psList.c
- Timestamp:
- Sep 8, 2004, 4:23:27 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psList.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psList.c
r1656 r1747 7 7 * @author Robert Daniel DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-0 8-28 03:00:16$9 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-09-09 02:23:27 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 49 49 50 50 if (data != NULL) { 51 psListAdd(list, data, PS_LIST_TAIL);51 psListAdd(list, PS_LIST_TAIL, data); 52 52 } 53 53 … … 81 81 } 82 82 83 bool psListAdd(psList* list, void *data, int where)83 bool psListAdd(psList* list, int location, void *data) 84 84 { 85 85 psListElem* position; … … 95 95 } 96 96 97 if ( where<= PS_LIST_UNKNOWN) {97 if (location <= PS_LIST_UNKNOWN) { 98 98 // / XXX What is the better way to communicate this failure to the caller? 99 psLogMsg(__func__, PS_LOG_WARN, "The given insert location (%i) for psListAdd is invalid.", where);99 psLogMsg(__func__, PS_LOG_WARN, "The given insert location (%i) for psListAdd is invalid.", location); 100 100 return false; 101 101 } … … 106 106 ; 107 107 108 if ( where > 0 && where> list->size) {108 if (location > 0 && location > list->size) { 109 109 psLogMsg(__func__, PS_LOG_WARN, 110 "Invalid index %d (only %d elements in psList); assuming tail.", where, list->size);111 where= PS_LIST_TAIL;112 } 113 114 if ( where== PS_LIST_TAIL || list->size == 0) {110 "Invalid index %d (only %d elements in psList); assuming tail.", location, list->size); 111 location = PS_LIST_TAIL; 112 } 113 114 if (location == PS_LIST_TAIL || list->size == 0) { 115 115 // insert the element at the end of the list 116 116 elem->prev = list->tail; … … 131 131 } else { 132 132 // move ourselves to the given position 133 listSetIterator(list, where, false);133 listSetIterator(list, location, false); 134 134 position = listGetIterator(list); 135 135 cursorIndex = listGetIteratorIndex(list); 136 136 137 137 if (position == NULL) { 138 psError(__func__, "%s failed to move cursor to specified location (%d)", __func__, where);138 psError(__func__, "%s failed to move cursor to specified location (%d)", __func__, location); 139 139 position = list->head; // since we no list->size != 0, this must be non-NULL 140 140 } … … 163 163 } 164 164 165 /*****************************************************************************/166 165 167 166 /* 168 167 * Remove an element from a list 169 168 */ 170 bool psListRemove(psList* list, void *data, int which)169 bool psListRemove(psList* list, int location, void *data) 171 170 { 172 171 psListElem* elem = NULL; // element to remove … … 181 180 ; 182 181 183 if ( which== PS_LIST_UNKNOWN) {182 if (location == PS_LIST_UNKNOWN) { 184 183 // search list for the data item. 185 184 … … 188 187 for (psListElem* ptr = list->head; ptr != NULL; ptr = ptr->next) { 189 188 if (ptr->data == data) { 190 which= i;189 location = i; 191 190 break; 192 191 } … … 194 193 } 195 194 196 if ( which== PS_LIST_UNKNOWN) {195 if (location == PS_LIST_UNKNOWN) { 197 196 psError(__func__, "Failed to find item in given psList."); 198 197 pthread_mutex_unlock(&list->lock) … … 202 201 } 203 202 // position the list's cursor to the desired location 204 listSetIterator(list, which, false);203 listSetIterator(list, location, false); 205 204 elem = listGetIterator(list); 206 205 cursorIndex = listGetIteratorIndex(list); 207 206 208 207 if (elem == NULL) { 209 psError(__func__, "Couldn't position to given index (%d) to remove element from list.", which);208 psError(__func__, "Couldn't position to given index (%d) to remove element from list.", location); 210 209 pthread_mutex_unlock(&list->lock) 211 210 ; … … 374 373 } 375 374 376 void *psListGet(psList* list, int which)375 void *psListGet(psList* list, int location) 377 376 { 378 377 psListElem* element; 379 378 380 psListSetIterator(list, which);379 psListSetIterator(list, location); 381 380 element = listGetIterator(list); 382 381 … … 449 448 n = arr->n; 450 449 for (int i = 0; i < n; i++) { 451 psListAdd(list, arr->data[i], PS_LIST_TAIL);450 psListAdd(list, PS_LIST_TAIL, arr->data[i]); 452 451 } 453 452
Note:
See TracChangeset
for help on using the changeset viewer.
