Changeset 1017 for trunk/psLib/src/collections/psList.h
- Timestamp:
- Jun 12, 2004, 12:15:39 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psList.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psList.h
r974 r1017 10 10 * @ingroup LinkedList 11 11 * 12 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-06-1 0 01:58:06$12 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-06-12 22:15:39 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 42 42 typedef struct psListElem 43 43 { 44 struct psListElem *prev; ///< previous link in list45 struct psListElem *next; ///< next link in list44 struct psListElem *prev; ///< previous link in list 45 struct psListElem *next; ///< next link in list 46 46 void *data; ///< real data item 47 47 } 48 48 psListElem; 49 49 50 /** Doubly-linked list */ 50 /** The psList Linked list structure. User should not allocate this struct 51 * directly; rather the psListAlloc should be used. 52 * 53 * @see psListAlloc, psListFree 54 */ 51 55 typedef struct 52 56 { 53 57 unsigned int size; ///< number of elements on list 54 psListElem* head; ///< first element on list (may be NULL)55 psListElem* tail; ///< last element on list (may be NULL)56 psListElem* iter; ///< iteration cursor58 psListElem* head; ///< first element on list (may be NULL) 59 psListElem* tail; ///< last element on list (may be NULL) 60 psListElem* iter; ///< iteration cursor 57 61 unsigned int iterIndex; ///< the numeric position of the iteration cursor in the list 58 62 pthread_mutex_t lock; ///< mutex to lock a node during changes … … 60 64 psList; 61 65 62 /** Constructor */ 63 psList *psListAlloc( 64 void *data ///< initial data item; may be NULL 66 /** Creates a psList linked list object. 67 * 68 * @return psList* A new psList object. 69 */ 70 psList* psListAlloc( 71 void *data 72 ///< initial data item; may be NULL if no an empty psList is desired 65 73 ) 66 74 ; 67 75 68 76 #include "psMemory.h" 69 /** Destructor */ 77 /** Destroys a psList linked list object. This also frees the elements of the 78 * list using the psFreeFcn given, if any. If no psFreeFcn is specified, 79 * the elements are just dereferenced via psMemDecrRefCounter(...). 80 * 81 */ 70 82 void psListFree( 71 psList* restrict list, ///< list to destroy83 psList* restrict list, ///< list to destroy 72 84 psFreeFcn elemFree ///< destructor for data on list 73 85 ); 74 86 75 /** Add to list */ 87 /** Adds an element to a psList at position given. 88 * 89 * @return psList* The psList with added data item. If list parameter is 90 * NULL, the return value will also be NULL. 91 */ 76 92 psList* psListAdd( 77 psList* restrict list, ///< list to add to (may be NULL)78 void* data, ///< data item to add 79 int where ///< index, PS_LIST_HEAD, or PS_LIST_TAIL93 psList* restrict list, ///< list to add to (if NULL, nothing is done) 94 void* data, ///< data item to add. If NULL, list is not modified. 95 int where ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location. 80 96 ); 81 97 82 /** Append to a list */ 98 /** Appends an item to a psList. 99 * 100 * @return psList* The psList with added data item. If list parameter is 101 * NULL, the return value will also be NULL. 102 */ 83 103 psList* psListAppend( 84 psList* restrict list, ///< list to append to (may be NULL)85 void *data ///< data item to add 104 psList* restrict list, ///< list to append to (if NULL, nothing is done) 105 void *data ///< data item to add. If NULL, list is not modified. 86 106 ); 87 107 88 /** Remove from a list */ 108 /** Remove an item from a list. If which parameter is PS_LIST_UNKNOWN, 109 * 110 * @return void* The data item that was removed. If NULL, no item was 111 * removed. 112 */ 89 113 void* psListRemove( 90 psList* restrict list, ///< list to remove element from 91 void *data, ///< data item to remove 92 int which ///< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV 114 psList* restrict list, 115 ///< list to remove element from 116 void *data, 117 ///< if which is PS_LIST_UNKNOWN, data item to find and remove, otherwise this is ignored. 118 int which 119 ///< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV, or numbered location. 93 120 ); 94 121 95 /** Retrieve from a list */ 122 /** Retrieve an item from a list. 123 * 124 * @return void* the item corresponding to the which parameter. If 125 * which is invalid (e.g., a numbered index greater 126 * than the list size or if the list is empty), a 127 * NULL is returned. 128 */ 96 129 void* psListGet( 97 130 psList* restrict list, ///< list to retrieve element from 98 int which ///< index of item, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN131 int which ///< index number, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN 99 132 ); 100 133 101 /** Set the iterator */ 134 /** Set the iterator of the list to a given position. If where is invalid the 135 * iterator position is not changed. 136 * 137 */ 102 138 void psListSetIterator( 103 139 psList* restrict list, ///< list to retrieve element from 104 int where ///< index , PS_LIST_HEAD, or PS_LIST_TAIL140 int where ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL 105 141 ); 106 142 107 /** Get next element relative to iter */ 143 /** Get next element relative to the iterator. This also moves the iterator to 144 * the next list position. 145 * 146 * @return void* the data item next on the list or NULL if the iterator 147 * is already pointing to the last element or the list 148 * parameter was NULL. 149 */ 108 150 void* psListGetNext( 109 151 psList* restrict list ///< list to retrieve element from 110 152 ); 111 153 112 /** Get current element at iter */ 154 /** Get current element according to the psList's iterator cursor. This does 155 * not move the iterator location. 156 * 157 * @return void* the data item cooresponding to current iterator 158 * cursor position of the list, or NULL if either the 159 * iterator is not valid or list parameter was NULL. 160 */ 113 161 void* psListGetCurrent( 114 162 psList* restrict list ///< list to retrieve element from 115 163 ); 116 164 117 /** Get prev element relative to iter */ 165 /** Get previous element relative to list's iterator. This also moves the 166 * iterator to the previous list position. 167 * 168 * @return void* the data item previous on the list or NULL if the iterator 169 * is already pointing to the first element or the list 170 * parameter was NULL. 171 */ 118 172 void* psListGetPrevious( 119 173 psList* restrict list ///< list to retrieve element from 120 174 ); 121 175 122 /** Convert doubly-linked list to an array */ 176 /** Convert a linked list to an array 177 * 178 * @return psVector* A new psVector populated with elements from the list, 179 * or NULL if the given dlist parameter is NULL. 180 */ 123 181 psVector* psListToVector( 124 182 psList *dlist ///< List to convert 125 183 ); 126 184 127 /** Convert array to a doubly-linked list */ 185 /** Convert array to a doubly-linked list 186 * 187 * @return psList* A new psList populated with elements formt the psVector, 188 * or NULL is the given arr parameter is NULL. 189 */ 128 190 psList* psVectorToList( 129 psVector* arr ///< vector to convert191 psVector* arr ///< vector to convert 130 192 ); 131 193
Note:
See TracChangeset
for help on using the changeset viewer.
