Changeset 1747
- Timestamp:
- Sep 8, 2004, 4:23:27 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 6 edited
-
collections/psHash.c (modified) (2 diffs)
-
collections/psList.c (modified) (13 diffs)
-
collections/psList.h (modified) (5 diffs)
-
types/psHash.c (modified) (2 diffs)
-
types/psList.c (modified) (13 diffs)
-
types/psList.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psHash.c
r1440 r1747 11 11 * @author George Gusciora, MHPCC 12 12 * 13 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-0 8-09 23:34:57 $13 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-09-09 02:23:27 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 61 61 ptr = table->buckets[i]; 62 62 while (ptr != NULL) { 63 psListAdd(myLinkList, ptr->key, PS_LIST_HEAD);63 psListAdd(myLinkList, PS_LIST_HEAD, ptr->key); 64 64 ptr = ptr->next; 65 65 } -
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 -
trunk/psLib/src/collections/psList.h
r1474 r1747 10 10 * @ingroup LinkedList 11 11 * 12 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-0 8-11 20:04:51$12 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-09-09 02:23:27 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 83 83 bool psListAdd( 84 84 psList* restrict list, ///< list to add to (if NULL, nothing is done) 85 void *data, ///< data item to add. If NULL, list is not modified.86 int where ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location.85 int location, ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location. 86 void *data ///< data item to add. If NULL, list is not modified. 87 87 ); 88 88 89 /** Remove an item from a list. If whichparameter is PS_LIST_UNKNOWN,89 /** Remove an item from a list. If location parameter is PS_LIST_UNKNOWN, 90 90 * 91 91 * @return bool TRUE if element is successfully removed, otherwise FALSE. … … 94 94 psList* restrict list, 95 95 ///< list to remove element from 96 void *data, 97 ///< if which is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored. 98 int which 96 int location, 99 97 ///< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV, or numbered location. 98 void *data 99 ///< if location is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored. 100 100 ); 101 101 102 102 /** Retrieve an item from a list. 103 103 * 104 * @return void* the item corresponding to the whichparameter. If105 * whichis invalid (e.g., a numbered index greater104 * @return void* the item corresponding to the location parameter. If 105 * location is invalid (e.g., a numbered index greater 106 106 * than the list size or if the list is empty), a 107 107 * NULL is returned. … … 109 109 void *psListGet( 110 110 psList* restrict list, ///< list to retrieve element from 111 int which///< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN111 int location ///< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN 112 112 ); 113 113 114 /** Set the iterator of the list to a given position. If whereis invalid the114 /** Set the iterator of the list to a given position. If location is invalid the 115 115 * iterator position is not changed. 116 116 * … … 118 118 void psListSetIterator( 119 119 psList* restrict list, ///< list to retrieve element from 120 int where///< index number, PS_LIST_HEAD, or PS_LIST_TAIL120 int location ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL 121 121 ); 122 122 -
trunk/psLib/src/types/psHash.c
r1440 r1747 11 11 * @author George Gusciora, MHPCC 12 12 * 13 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-0 8-09 23:34:57 $13 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-09-09 02:23:27 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 61 61 ptr = table->buckets[i]; 62 62 while (ptr != NULL) { 63 psListAdd(myLinkList, ptr->key, PS_LIST_HEAD);63 psListAdd(myLinkList, PS_LIST_HEAD, ptr->key); 64 64 ptr = ptr->next; 65 65 } -
trunk/psLib/src/types/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 -
trunk/psLib/src/types/psList.h
r1474 r1747 10 10 * @ingroup LinkedList 11 11 * 12 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-0 8-11 20:04:51$12 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-09-09 02:23:27 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 83 83 bool psListAdd( 84 84 psList* restrict list, ///< list to add to (if NULL, nothing is done) 85 void *data, ///< data item to add. If NULL, list is not modified.86 int where ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location.85 int location, ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location. 86 void *data ///< data item to add. If NULL, list is not modified. 87 87 ); 88 88 89 /** Remove an item from a list. If whichparameter is PS_LIST_UNKNOWN,89 /** Remove an item from a list. If location parameter is PS_LIST_UNKNOWN, 90 90 * 91 91 * @return bool TRUE if element is successfully removed, otherwise FALSE. … … 94 94 psList* restrict list, 95 95 ///< list to remove element from 96 void *data, 97 ///< if which is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored. 98 int which 96 int location, 99 97 ///< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV, or numbered location. 98 void *data 99 ///< if location is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored. 100 100 ); 101 101 102 102 /** Retrieve an item from a list. 103 103 * 104 * @return void* the item corresponding to the whichparameter. If105 * whichis invalid (e.g., a numbered index greater104 * @return void* the item corresponding to the location parameter. If 105 * location is invalid (e.g., a numbered index greater 106 106 * than the list size or if the list is empty), a 107 107 * NULL is returned. … … 109 109 void *psListGet( 110 110 psList* restrict list, ///< list to retrieve element from 111 int which///< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN111 int location ///< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN 112 112 ); 113 113 114 /** Set the iterator of the list to a given position. If whereis invalid the114 /** Set the iterator of the list to a given position. If location is invalid the 115 115 * iterator position is not changed. 116 116 * … … 118 118 void psListSetIterator( 119 119 psList* restrict list, ///< list to retrieve element from 120 int where///< index number, PS_LIST_HEAD, or PS_LIST_TAIL120 int location ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL 121 121 ); 122 122
Note:
See TracChangeset
for help on using the changeset viewer.
