Changeset 2375 for trunk/psLib/src/collections
- Timestamp:
- Nov 16, 2004, 10:00:21 AM (22 years ago)
- Location:
- trunk/psLib/src/collections
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psList.c
r2273 r2375 6 6 * @author Robert Daniel DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-11- 04 01:04:57$8 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-11-16 20:00:20 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 42 42 list->size = 0; 43 43 list->head = list->tail = NULL; 44 list-> iter = ITER_INIT_HEAD;45 list-> iterIndex = PS_LIST_HEAD;44 list->p_iter = ITER_INIT_HEAD; 45 list->p_iterIndex = PS_LIST_HEAD; 46 46 47 47 pthread_mutex_init(&(list->lock), NULL) … … 127 127 128 128 list->size++; 129 list-> iter = elem;130 list-> iterIndex = list->size - 1;129 list->p_iter = elem; 130 list->p_iterIndex = list->size - 1; 131 131 } else { 132 132 // move ourselves to the given position … … 152 152 153 153 list->size++; 154 list-> iter = elem;155 list-> iterIndex = cursorIndex;154 list->p_iter = elem; 155 list->p_iterIndex = cursorIndex; 156 156 } 157 157 … … 227 227 // removed tail, so iter should be the last element of list to keep it valid 228 228 if (list->size > 0) { 229 list-> iter = list->tail;230 list-> iterIndex = list->size - 1;229 list->p_iter = list->tail; 230 list->p_iterIndex = list->size - 1; 231 231 } else { 232 list-> iter = ITER_INIT_TAIL;232 list->p_iter = ITER_INIT_TAIL; 233 233 } 234 234 } else { 235 235 elem->next->prev = elem->prev; 236 list-> iter = elem->next;237 list-> iterIndex = cursorIndex;236 list->p_iter = elem->next; 237 list->p_iterIndex = cursorIndex; 238 238 } 239 239 … … 275 275 276 276 if (where >= (psS32)list->size) { 277 list-> iter = NULL;277 list->p_iter = NULL; 278 278 if (lockList) { 279 279 pthread_mutex_unlock(&list->lock) … … 285 285 switch (where) { 286 286 case PS_LIST_HEAD: 287 list-> iter = ITER_INIT_HEAD;287 list->p_iter = ITER_INIT_HEAD; 288 288 break; 289 289 290 290 case PS_LIST_TAIL: 291 list-> iter = ITER_INIT_TAIL;291 list->p_iter = ITER_INIT_TAIL; 292 292 break; 293 293 … … 297 297 298 298 if (cursor != NULL) { 299 list-> iter = cursor->prev;300 list-> iterIndex = position - 1;299 list->p_iter = cursor->prev; 300 list->p_iterIndex = position - 1; 301 301 } 302 302 break; … … 307 307 308 308 if (cursor != NULL) { 309 list-> iter = cursor->next;310 list-> iterIndex = position + 1;309 list->p_iter = cursor->next; 310 list->p_iterIndex = position + 1; 311 311 } 312 312 break; … … 322 322 cursor = listGetIterator(list); 323 323 if (cursor == NULL) { // reset the iterator if it is invalid 324 list-> iter = ITER_INIT_HEAD;325 list-> iterIndex = 0;324 list->p_iter = ITER_INIT_HEAD; 325 list->p_iterIndex = 0; 326 326 } 327 327 … … 357 357 } 358 358 359 if (list-> iter == ITER_INIT_HEAD) {359 if (list->p_iter == ITER_INIT_HEAD) { 360 360 return list->head; 361 } else if (list-> iter == ITER_INIT_TAIL) {361 } else if (list->p_iter == ITER_INIT_TAIL) { 362 362 return list->tail; 363 363 } else { 364 return list-> iter;364 return list->p_iter; 365 365 } 366 366 } … … 368 368 psS32 listGetIteratorIndex(psList* list) 369 369 { 370 if (list-> iter == ITER_INIT_HEAD) {370 if (list->p_iter == ITER_INIT_HEAD) { 371 371 return 0; 372 } else if (list-> iter == ITER_INIT_TAIL) {372 } else if (list->p_iter == ITER_INIT_TAIL) { 373 373 return list->size - 1; 374 374 } else { 375 return list-> iterIndex;375 return list->p_iterIndex; 376 376 } 377 377 } -
trunk/psLib/src/collections/psList.h
r2204 r2375 10 10 * @ingroup LinkedList 11 11 * 12 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-1 0-27 00:57:31$12 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-11-16 20:00:20 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 52 52 * directly; rather the psListAlloc should be used. 53 53 * 54 * @see psListAlloc , psListFree54 * @see psListAlloc 55 55 */ 56 56 typedef struct 57 57 { 58 psU32 size; ///< number of elements on list58 psU32 size; ///< number of elements on list 59 59 psListElem* head; ///< first element on list (may be NULL) 60 60 psListElem* tail; ///< last element on list (may be NULL) 61 psListElem* iter; ///< iteration cursor 62 psU32 iterIndex; ///< the numeric position of the iteration cursor in the list 61 psArray* iterators; ///< iterators 63 62 pthread_mutex_t lock; ///< mutex to lock a node during changes 63 psListElem* p_iter; ///< internal cursor for increased performance index accessing 64 int p_iterIndex; ///< index position of the iter. 64 65 } 65 66 psList; 67 68 /** The psList iterator structure. This should be allocated via 69 * psListIteratorAlloc and not directly. 70 * 71 * The life span of a psListIterator object is ended by either a psFree 72 * of this structure OR psFree of the psList in which it operates on. 73 * 74 * @see psListIteratorAlloc, psListIteratorSet, psListGetNext, psListGetPrevious 75 */ 76 typedef struct 77 { 78 psList* list; ///< List iterator to works on 79 psU32 number; ///< List iterator number 80 psListElem* cursor; ///< current cursor position 81 bool offEnd; ///< Iterator off the end? 82 } 83 psListIterator; 84 66 85 67 86 /** Creates a psList linked list object.
Note:
See TracChangeset
for help on using the changeset viewer.
