IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 7, 2004, 4:18:15 PM (22 years ago)
Author:
desonia
Message:

added list<->vector conversion routines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psDlist.c

    r900 r912  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-07 23:18:21 $
     8 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-08 02:18:15 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    413413}
    414414
    415 #if 0
    416415/*
    417416 * Convert a psDlist to/from a psVoidPtrArray
    418417 */
    419 psVoidPtrArray *psDlistToArray(psDlist *restrict dlist)
    420 {
     418psVector* psDlistToVector(psDlist* restrict dlist)
     419{
     420    psDlistElem* ptr;
     421    unsigned int n;
     422
    421423    if (dlist == NULL) {
    422424        return NULL;
    423425    }
    424426
    425     psVoidPtrArray *restrict arr = psVoidPtrArrayAlloc(dlist->size, dlist->size);
    426 
    427     psDlistElem *ptr = dlist->head;
    428     for (int i = 0, n = dlist->size; i < n; i++) {
    429         arr->arr[i] = ptr->data;
    430 
    431         ptr->data = NULL;
     427    psVector* restrict arr = psVectorAlloc(dlist->size, PS_TYPE_PTR);
     428    arr->n = arr->nalloc;
     429
     430    ptr = dlist->head;
     431    n = dlist->size;
     432    for (int i = 0; i < n; i++) {
     433        arr->data.PTR[i] = psMemIncrRefCounter(ptr->data);
    432434        ptr = ptr->next;
    433435    }
    434436
    435     psDlistFree(dlist, NULL);
    436 
    437437    return arr;
    438438}
    439439
    440 psDlist *psArrayToDlist(psVoidPtrArray *arr)
    441 {
    442     psDlist *list = psDlistAlloc(NULL); // list of elements
    443 
    444     for (int i = 0, n = arr->size; i < n; i++) {
    445         psDlistAppend(list,
    446                       psMemDecrRefCounter(arr->arr[i])); // it's already Incr
    447         arr->arr[i] = NULL;
    448     }
    449 
    450     psVoidPtrArrayFree(arr, NULL);
     440psDlist* psVectorToDlist(psVector* arr)
     441{
     442    unsigned int n;
     443    psDlist* list; // list of elements
     444
     445    if (arr == NULL) {
     446        return NULL;
     447    }
     448
     449    if (arr->type.type != PS_TYPE_PTR) {
     450        psError(__func__,"Can not convert a non pointer-vector to a linked list.");
     451        return NULL;
     452    }
     453
     454    list = psDlistAlloc(NULL);
     455    n = arr->n;
     456    for (int i = 0; i < n; i++) {
     457        psDlistAppend(list,arr->data.PTR[i]);
     458    }
    451459
    452460    return list;
    453461}
    454 
    455 #endif
Note: See TracChangeset for help on using the changeset viewer.