IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 912


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

added list<->vector conversion routines.

Location:
trunk/psLib/src/collections
Files:
2 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
  • trunk/psLib/src/collections/psDlist.h

    r886 r912  
    99 *  @author Robert Daniel DeSonia, MHPCC
    1010 *
    11  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-06-05 19:12:51 $
     11 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-08 02:18:15 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1616
    1717#include <pthread.h>                   // we need a mutex to make this stuff thread safe.
     18
     19#include "psVector.h"
    1820
    1921/** Special values of index into list
     
    7981/** Append to a list */
    8082psDlist* psDlistAppend(
    81     psDlist* restrict list,                      ///< list to append to (may be NULL)
     83    psDlist* restrict list,             ///< list to append to (may be NULL)
    8284    void *data                          ///< data item to add
    8385);
     
    118120
    119121/** Convert doubly-linked list to an array */
    120 #if 0
    121 psVoidPtrArray *psDlistToArray(
     122psVector* psDlistToVector(
    122123    psDlist *dlist                      ///< List to convert
    123124);
    124125
    125126/** Convert array to a doubly-linked list */
    126 psDlist *psArrayToDlist(
    127     psVoidPtrArray *arr                 ///< Array to convert
     127psDlist* psVectorToDlist(
     128    psVector* arr                       ///< vector to convert
    128129);
    129 #endif
    130130
    131131/// @} End of DataGroup Functions
Note: See TracChangeset for help on using the changeset viewer.