Changeset 2204 for trunk/psLib/src/collections/psList.c
- Timestamp:
- Oct 26, 2004, 2:57:34 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psList.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psList.c
r1807 r2204 6 6 * @author Robert Daniel DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1. 19$ $Name: not supported by cvs2svn $9 * @date $Date: 2004- 09-14 20:01:52$8 * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-27 00:57:31 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 13 13 14 14 #include <stdlib.h> 15 #include <stdbool.h>16 15 #include <stdio.h> 17 16 #include <pthread.h> // we need a mutex to make this stuff thread safe. … … 26 25 #include "psCollectionsErrors.h" 27 26 28 #define ITER_INIT_HEAD (( void *)1) // next iteration should return head29 #define ITER_INIT_TAIL (( void *)2) // next iteration should return tail27 #define ITER_INIT_HEAD ((psPtr )1) // next iteration should return head 28 #define ITER_INIT_TAIL ((psPtr )2) // next iteration should return tail 30 29 31 30 // private functions. 32 31 static psListElem* listGetIterator(psList* list); 33 static intlistGetIteratorIndex(psList* list);34 static void listSetIterator(psList* list, int where, bool lockList);32 static psS32 listGetIteratorIndex(psList* list); 33 static void listSetIterator(psList* list, psS32 where, psBool lockList); 35 34 static void listFree(psList* list); 36 35 37 psList* psListAlloc( void *data)36 psList* psListAlloc(psPtr data) 38 37 { 39 38 psList* list = psAlloc(sizeof(psList)); … … 82 81 } 83 82 84 bool psListAdd(psList* list, int location, void *data)83 psBool psListAdd(psList* list, psS32 location, psPtr data) 85 84 { 86 85 psListElem* position; 87 86 psListElem* elem; 88 intcursorIndex = 0;87 psS32 cursorIndex = 0; 89 88 90 89 if (list == NULL) { … … 168 167 * Remove an element from a list 169 168 */ 170 bool psListRemove(psList* list, int location, void *data)169 psBool psListRemove(psList* list, psS32 location, psPtr data) 171 170 { 172 171 psListElem* elem = NULL; // element to remove 173 intcursorIndex = 0;172 psS32 cursorIndex = 0; 174 173 175 174 if (list == NULL) { … … 184 183 // search list for the data item. 185 184 186 inti = 0; // index185 psS32 i = 0; // index 187 186 188 187 for (psListElem* ptr = list->head; ptr != NULL; ptr = ptr->next) { … … 247 246 } 248 247 249 void psListSetIterator(psList* list, intwhere)248 void psListSetIterator(psList* list, psS32 where) 250 249 { 251 250 listSetIterator(list, where, true); 252 251 } 253 252 254 static void listSetIterator(psList* list, int where, bool lockList)253 static void listSetIterator(psList* list, psS32 where, psBool lockList) 255 254 { 256 255 psListElem* cursor; 257 intposition;256 psS32 position; 258 257 259 258 if (list == NULL) { … … 272 271 } 273 272 274 if (where >= ( int)list->size) {273 if (where >= (psS32)list->size) { 275 274 list->iter = NULL; 276 275 if (lockList) { … … 323 322 } 324 323 325 intposition = listGetIteratorIndex(list);324 psS32 position = listGetIteratorIndex(list); 326 325 327 326 if (where < position) { 328 intdiff = position - where;329 330 for ( intcount = 0; count < diff; count++) {327 psS32 diff = position - where; 328 329 for (psS32 count = 0; count < diff; count++) { 331 330 listSetIterator(list, PS_LIST_PREVIOUS, false); 332 331 } 333 332 } else { 334 intdiff = where - position;335 336 for ( intcount = 0; count < diff; count++) {333 psS32 diff = where - position; 334 335 for (psS32 count = 0; count < diff; count++) { 337 336 listSetIterator(list, PS_LIST_NEXT, false); 338 337 } … … 363 362 } 364 363 365 intlistGetIteratorIndex(psList* list)364 psS32 listGetIteratorIndex(psList* list) 366 365 { 367 366 if (list->iter == ITER_INIT_HEAD) { … … 374 373 } 375 374 376 void *psListGet(psList* list, intlocation)375 psPtr psListGet(psList* list, psS32 location) 377 376 { 378 377 psListElem* element; … … 391 390 * and now return the previous/next element of the list 392 391 */ 393 void *psListGetNext(psList* list)392 psPtr psListGetNext(psList* list) 394 393 { 395 394 return psListGet(list, PS_LIST_NEXT); 396 395 } 397 396 398 void *psListGetPrevious(psList* list)397 psPtr psListGetPrevious(psList* list) 399 398 { 400 399 return psListGet(list, PS_LIST_PREVIOUS); 401 400 } 402 401 403 void *psListGetCurrent(psList* list)402 psPtr psListGetCurrent(psList* list) 404 403 { 405 404 return psListGet(list, PS_LIST_CURRENT); … … 412 411 { 413 412 psListElem* ptr; 414 unsigned intn;413 psU32 n; 415 414 psArray* restrict arr; 416 415 … … 429 428 ptr = list->head; 430 429 n = list->size; 431 for ( inti = 0; i < n; i++) {430 for (psS32 i = 0; i < n; i++) { 432 431 arr->data[i] = psMemIncrRefCounter(ptr->data); 433 432 ptr = ptr->next; … … 439 438 psList* psArrayToList(psArray* arr) 440 439 { 441 unsigned intn;440 psU32 n; 442 441 psList* list; // list of elements 443 442 … … 448 447 list = psListAlloc(NULL); 449 448 n = arr->n; 450 for ( inti = 0; i < n; i++) {449 for (psS32 i = 0; i < n; i++) { 451 450 psListAdd(list, PS_LIST_TAIL, arr->data[i]); 452 451 }
Note:
See TracChangeset
for help on using the changeset viewer.
