Changeset 506 for trunk/psLib/src/sysUtils/psDList.h
- Timestamp:
- Apr 22, 2004, 2:19:42 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sysUtils/psDList.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sysUtils/psDList.h
r484 r506 9 9 * @author Robert Daniel DeSonia, MHPCC 10 10 * 11 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-04-2 1 00:15:17$11 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-04-23 00:19:42 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 15 */ 16 16 17 /** Special values of index into list */ 17 #include <pthread.h> // we need a mutex to make this stuff thread safe. 18 19 /** Special values of index into list 20 * 21 * This list of possible list position values should be contiguous non-positive values ending with 22 * PS_DLIST_UNKNOWN. Any value less-than-or-equal-to PS_DLIST_UNKNOWN is considered a undefined position. 23 * 24 */ 18 25 enum { 19 26 PS_DLIST_HEAD = 0, ///< at head 20 27 PS_DLIST_TAIL = -1, ///< at tail 21 PS_DLIST_ UNKNOWN = -2, ///< unknown position22 PS_DLIST_ PREVIOUS = -3, ///< previouselement23 PS_DLIST_ CURRENT = -4, ///< current element24 PS_DLIST_ NEXT = -5 ///< next element28 PS_DLIST_PREVIOUS = -2, ///< previous element 29 PS_DLIST_CURRENT = -3, ///< current element 30 PS_DLIST_NEXT = -4, ///< next element 31 PS_DLIST_UNKNOWN = -5 ///< unknown position (should be last in enum list) 25 32 }; 26 33 … … 37 44 typedef struct 38 45 { 39 int n;///< number of elements on list46 unsigned int size; ///< number of elements on list 40 47 psDlistElem* head; ///< first element on list (may be NULL) 41 48 psDlistElem* tail; ///< last element on list (may be NULL) 42 49 psDlistElem* iter; ///< iteration cursor 43 int iterIndex; 50 unsigned int iterIndex; ///< the numeric position of the iteration cursor in the list 51 pthread_mutex_t lock; ///< mutex to lock a node during changes 44 52 } 45 53 psDlist; … … 51 59 /** Constructor */ 52 60 psDlist *psDlistAlloc( 53 void *data ///< initial data item; may be NULL 54 ); 61 void *data ///< initial data item; may be NULL 62 ) 63 ; 55 64 56 65 /** Destructor */ 57 66 void psDlistFree( 58 psDlist *list,///< list to destroy59 void (*elemFree)(void *) ///< destructor for data on list67 psDlist* restrict list, ///< list to destroy 68 void (*elemFree)(void *) ///< destructor for data on list 60 69 ); 61 70 62 71 /** Add to list */ 63 psDlist *psDlistAdd(64 psDlist *list,///< list to add to (may be NULL)65 void *data,///< data item to add66 int where ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL72 psDlist* psDlistAdd( 73 psDlist* restrict list, ///< list to add to (may be NULL) 74 void* data, ///< data item to add 75 int where ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL 67 76 ); 68 77 69 78 /** Append to a list */ 70 psDlist *psDlistAppend(71 psDlist *list,///< list to append to (may be NULL)72 void *data ///< data item to add79 psDlist* psDlistAppend( 80 psDlist* restrict list, ///< list to append to (may be NULL) 81 void *data ///< data item to add 73 82 ); 74 83 75 84 /** Remove from a list */ 76 void *psDlistRemove(77 psDlist *list,///< list to remove element from78 void *data, ///< data item to remove79 int which ///< index of item, or PS_DLIST_UNKNOWN, PS_DLIST_NEXT, PS_DLIST_PREV85 void* psDlistRemove( 86 psDlist* restrict list, ///< list to remove element from 87 void *data, ///< data item to remove 88 int which ///< index of item, or PS_DLIST_UNKNOWN, PS_DLIST_NEXT, PS_DLIST_PREV 80 89 ); 81 90 82 91 /** Retrieve from a list */ 83 void *psDlistGet(84 const psDlist *list,///< list to retrieve element from85 int which ///< index of item, or PS_DLIST_NEXT, PS_DLIST_PREV, PS_DLIST_UNKNOWN92 void* psDlistGet( 93 psDlist* restrict list, ///< list to retrieve element from 94 int which ///< index of item, or PS_DLIST_NEXT, PS_DLIST_PREV, PS_DLIST_UNKNOWN 86 95 ); 87 96 88 97 /** Set the iterator */ 89 98 void psDlistSetIterator( 90 psDlist *list,///< list to retrieve element from91 int where ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL99 psDlist* restrict list, ///< list to retrieve element from 100 int where ///< index, PS_DLIST_HEAD, or PS_DLIST_TAIL 92 101 ); 93 102 94 103 /** Get next element relative to iter */ 95 void *psDlistGetNext(96 psDlist *list///< list to retrieve element from104 void* psDlistGetNext( 105 psDlist* restrict list ///< list to retrieve element from 97 106 ); 98 107 99 108 /** Get current element at iter */ 100 void *psDlistGetCurrent(101 psDlist *list///< list to retrieve element from109 void* psDlistGetCurrent( 110 psDlist* restrict list ///< list to retrieve element from 102 111 ); 103 112 104 113 /** Get prev element relative to iter */ 105 void *psDlistGetPrevious(106 psDlist *list///< list to retrieve element from114 void* psDlistGetPrevious( 115 psDlist* restrict list ///< list to retrieve element from 107 116 ); 108 117 … … 110 119 #if 0 111 120 psVoidPtrArray *psDlistToArray( 112 psDlist *dlist ///< List to convert121 psDlist *dlist ///< List to convert 113 122 ); 114 123 115 124 /** Convert array to a doubly-linked list */ 116 125 psDlist *psArrayToDlist( 117 psVoidPtrArray *arr ///< Array to convert126 psVoidPtrArray *arr ///< Array to convert 118 127 ); 119 128 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
