Changeset 1580 for trunk/archive/pslib/include/psList.h
- Timestamp:
- Aug 18, 2004, 4:01:44 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/archive/pslib/include/psList.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/pslib/include/psList.h
r1579 r1580 1 #if !defined(PS_ DLIST_H)2 #define PS_ DLIST_H1 #if !defined(PS_LIST_H) 2 #define PS_LIST_H 3 3 4 /** \file ps Dlist.h4 /** \file psList.h 5 5 * \brief Support for doubly linked lists 6 6 * \ingroup DataGroup … … 8 8 9 9 /** Doubly-linked list element */ 10 typedef struct ps DlistElem {11 struct ps DlistElem *prev; ///< previous link in list12 struct ps DlistElem *next; ///< next link in list10 typedef struct psListElem { 11 struct psListElem *prev; ///< previous link in list 12 struct psListElem *next; ///< next link in list 13 13 void *data; ///< real data item 14 } ps DlistElem;14 } psListElem; 15 15 16 16 /** Doubly-linked list */ 17 17 typedef struct { 18 int n; ///< number of elements on list 19 psDlistElem *head; ///< first element on list (may be NULL) 20 psDlistElem *tail; ///< last element on list (may be NULL) 21 psDlistElem *iter; ///< iteration cursor 22 } psDlist; 18 unsigned int size; ///< number of elements on list 19 psListElem *head; ///< first element on list (may be NULL) 20 psListElem *tail; ///< last element on list (may be NULL) 21 psListElem *iter; ///< iteration cursor 22 unsigned int iterIndex; ///< the numeric position of the iteration cursor in the list 23 pthread_mutex_t lock; ///< mutex to lock a node during changes 24 } psList; 23 25 24 26 /** Special values of index into list */ 25 27 enum { 26 PS_ DLIST_HEAD = 0, ///< at head27 PS_ DLIST_TAIL = -1, ///< at tail28 PS_ DLIST_UNKNOWN = -2, ///< unknown position29 PS_ DLIST_PREV = -3, ///< previous element30 PS_ DLIST_NEXT = -4 ///< next element28 PS_LIST_HEAD = 0, ///< at head 29 PS_LIST_TAIL = -1, ///< at tail 30 PS_LIST_UNKNOWN = -2, ///< unknown position 31 PS_LIST_PREV = -3, ///< previous element 32 PS_LIST_NEXT = -4 ///< next element 31 33 }; 32 34 … … 37 39 38 40 /** Constructor */ 39 ps Dlist *psDlistAlloc(void *data)///< initial data item; may be NULL41 psList *psListAlloc(void *data) ///< initial data item; may be NULL 40 42 ; 41 43 42 44 /** Destructor */ 43 void ps DlistFree(psDlist *list, ///< list to destroy45 void psListFree(psList *list, ///< list to destroy 44 46 void (*elemFree)(void *)) ///< destructor for data on list 45 47 ; … … 48 50 49 51 /** Add to list */ 50 psDlist *psDlistAdd(psDlist *list, ///< list to add to (may be NULL) 51 void *data, ///< data item to add 52 int where) ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL 53 ; 54 55 /** Append to a list */ 56 psDlist *psDlistAppend(psDlist *list, ///< list to append to (may be NULL) 57 void *data) ///< data item to add 52 bool *psListAdd(psList *list, ///< list to add to (may be NULL) 53 void *data, ///< data item to add 54 int where) ///< index, PS_LIST_HEAD, or PS_LIST_TAIL 58 55 ; 59 56 60 57 /** Remove from a list */ 61 void *psDlistRemove(psDlist *list, ///< list to remove element from62 void *data, ///< data item to remove63 int which) ///< index of item, or PS_DLIST_UNKNOWN, PS_DLIST_NEXT, PS_DLIST_PREV58 bool *psListRemove(psList *list, ///< list to remove element from 59 void *data, ///< data item to remove 60 int which) ///< index of item, or PS_LIST_UNKNOWN, PS_LIST_NEXT, PS_LIST_PREV 64 61 ; 65 62 66 63 /** Retrieve from a list */ 67 void *ps DlistGet(const psDlist *list, ///< list to retrieve element from68 int which) ///< index of item, or PS_DLIST_NEXT, PS_DLIST_PREV, PS_DLIST_UNKNOWN64 void *psListGet(const psList *list, ///< list to retrieve element from 65 int which) ///< index of item, or PS_LIST_NEXT, PS_LIST_PREV, PS_LIST_UNKNOWN 69 66 ; 70 67 68 /** Convert doubly-linked list to an array of (void *) */ 69 psArray *psListToArray(psList *list) ///< List to convert 70 ; 71 72 /** Convert array to a doubly-linked list */ 73 psList *psArrayToList(psArray *array) ///< array of (void *) to convert 74 ; 75 76 /** Sort a list. */ 77 psList *psListSort(psList *list, ///< List to sort 78 int (*compare)(const void **a, const void **b) // Function to compare two list elements 79 ); 80 71 81 /** Set the iterator */ 72 void ps DlistSetIterator(psDlist *list, ///< list to retrieve element from73 int where, ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL74 int which) ///< the desired iterator82 void psListSetIterator(psList *list, ///< list to retrieve element from 83 int where, ///< index, PS_LIST_HEAD, or PS_LIST_TAIL 84 int which) ///< the desired iterator 75 85 ; 76 86 77 87 /** Get next element relative to iter */ 78 void *ps DlistGetNext(psDlist *list, ///< list to retrieve element from79 int which) ///< the desired iterator88 void *psListGetNext(psList *list, ///< list to retrieve element from 89 int which) ///< the desired iterator 80 90 ; 81 91 82 92 /** Get prev element relative to iter */ 83 void *ps DlistGetPrev(psDlist *list, ///< list to retrieve element from84 int which)///< the desired iterator93 void *psListGetPrevious(psList *list, ///< list to retrieve element from 94 int which) ///< the desired iterator 85 95 ; 86 87 /** Convert doubly-linked list to a vector of (void *) */88 psVector *psDlistToVector(psDlist *dlist) ///< List to convert89 ;90 91 /** Convert array to a doubly-linked list */92 psDlist *psArrayToDlist(psVector *vector) ///< vector of (void *) to convert93 ;94 95 /** Sort a list. */96 psDlist *psDlistSort(psDlist *list, ///< List to sort97 int (*compare)(const void *a, const void *b) // Function to compare two list elements98 );99 96 100 97 /* \} */ // End of DataGroup Functions
Note:
See TracChangeset
for help on using the changeset viewer.
