IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1228


Ignore:
Timestamp:
Jul 15, 2004, 12:18:02 PM (22 years ago)
Author:
desonia
Message:

extracted the vector of pointers functionality to a new object, psArray.

Location:
trunk/psLib/src
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/Makefile

    r1205 r1228  
    33##  Makefile:   collections
    44##
    5 ##  $Revision: 1.23 $  $Name: not supported by cvs2svn $
    6 ##  $Date: 2004-07-09 21:48:07 $
     5##  $Revision: 1.24 $  $Name: not supported by cvs2svn $
     6##  $Date: 2004-07-15 22:18:02 $
    77##
    88##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636           psList.o \
    3737           psScalar.o \
    38            psCompare.o
     38           psCompare.o \
     39           psArray.o
    3940
    4041# Define PHONY target "all" which will make all the necessary items
  • trunk/psLib/src/collections/psList.c

    r1193 r1228  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-07-08 01:05:00 $
     8 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-15 22:18:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    401401 * Convert a psList to/from a psVoidPtrArray
    402402 */
    403 psVector* psListToVector(psList* restrict list)
     403psArray* psListToArray(psList* restrict list)
    404404{
    405405    psListElem* ptr;
    406406    unsigned int n;
    407     psVector* restrict arr;
     407    psArray* restrict arr;
    408408
    409409    if (list == NULL) {
     
    412412
    413413    if (list->size > 0) {
    414         arr = psVectorAlloc(list->size, PS_TYPE_PTR);
    415     } else {
    416         arr = psVectorAlloc(1, PS_TYPE_PTR);
     414        arr = psArrayAlloc(list->size);
     415    } else {
     416        arr = psArrayAlloc(1);
    417417    }
    418418
     
    422422    n = list->size;
    423423    for (int i = 0; i < n; i++) {
    424         arr->data.PTR[i] = psMemIncrRefCounter(ptr->data);
     424        arr->data[i] = psMemIncrRefCounter(ptr->data);
    425425        ptr = ptr->next;
    426426    }
     
    429429}
    430430
    431 psList* psVectorToList(psVector* arr)
     431psList* psArrayToList(psArray* arr)
    432432{
    433433    unsigned int n;
     
    435435
    436436    if (arr == NULL) {
    437         return NULL;
    438     }
    439 
    440     if (arr->type.type != PS_TYPE_PTR) {
    441         psError(__func__,"Can not convert a non pointer-vector to a linked list.");
    442437        return NULL;
    443438    }
     
    446441    n = arr->n;
    447442    for (int i = 0; i < n; i++) {
    448         psListAdd(list,arr->data.PTR[i],PS_LIST_TAIL);
     443        psListAdd(list,arr->data[i],PS_LIST_TAIL);
    449444    }
    450445
     
    455450psList* psListSort(psList* list, psComparePtrFcn compare)
    456451{
    457     psVector* vector;
     452    psArray* arr;
    458453    if (list == NULL) {
    459454        return NULL;
     
    461456
    462457    // convert to indexable vector for use by qsort.
    463     vector = psListToVector(list);
     458    arr = psListToArray(list);
    464459    psFree(list);
    465460
    466     qsort(vector->data.V, vector->n, sizeof(void*),
    467           (int(*)(const void *, const void *))compare);
     461    arr = psArraySort(arr,compare);
    468462
    469463    // convert back to linked list
    470     list = psVectorToList(vector);
    471     psFree(vector);
     464    list = psArrayToList(arr);
     465    psFree(arr);
    472466
    473467    return list;
  • trunk/psLib/src/collections/psList.d

    r1111 r1228  
    11psList.o psList.d : psList.c ../sysUtils/psError.h ../sysUtils/psAbort.h \
    2   ../sysUtils/psMemory.h psList.h psCompare.h psVector.h psType.h \
     2  ../sysUtils/psMemory.h psList.h psCompare.h psArray.h psType.h \
    33  ../sysUtils/psTrace.h ../sysUtils/psLogMsg.h
  • trunk/psLib/src/collections/psList.h

    r1193 r1228  
    1010 *  @ingroup LinkedList
    1111 *
    12  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-08 01:05:00 $
     12 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-15 22:18:02 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2020
    2121#include "psCompare.h"
    22 #include "psVector.h"
     22#include "psArray.h"
    2323
    2424/** @addtogroup LinkedList
     
    156156/** Convert a linked list to an array
    157157 *
    158  *  @return psVector*   A new psVector populated with elements from the list,
     158 *  @return psArray*   A new psArray populated with elements from the list,
    159159 *                      or NULL if the given dlist parameter is NULL.
    160160 */
    161 psVector* psListToVector(
     161psArray* psListToArray(
    162162    psList *dlist                      ///< List to convert
    163163);
     
    165165/** Convert array to a doubly-linked list
    166166 *
    167  *  @return psList*     A new psList populated with elements formt the psVector,
     167 *  @return psList*     A new psList populated with elements formt the psArray,
    168168 *                      or NULL is the given arr parameter is NULL.
    169169 */
    170 psList* psVectorToList(
    171     psVector* arr                      ///< vector to convert
     170psList* psArrayToList(
     171    psArray* arr                      ///< vector to convert
    172172);
    173173
  • trunk/psLib/src/collections/psVector.c

    r1103 r1228  
    88 *  @author Ross Harman, MHPCC
    99 *
    10  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-06-26 00:24:30 $
     10 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-07-15 22:18:02 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    100100        elementSize = PSELEMTYPE_SIZEOF(elemType);
    101101        if(nalloc < in->n) {
    102             if (elemType == PS_TYPE_PTR) {
    103                 for (int i = nalloc; i < in->n; i++) {   // For reduction in vector size
    104                     psMemDecrRefCounter(in->data.PTR[i]);
    105                 }
    106             }
    107102            in->n = nalloc;
    108103        }
     
    139134
    140135
    141     // if vector of pointers, dereference old values.
    142     if (elemType == PS_TYPE_PTR) {
    143         for (int i = 0; i < in->n; i++) {   // For reduction in vector size
    144             psMemDecrRefCounter(in->data.PTR[i]);
    145             in->data.PTR[i] = NULL;
    146         }
    147     }
    148 
    149136    in->data.V = psRealloc(in->data.V,nalloc*PSELEMTYPE_SIZEOF(type));
    150137
     
    162149    }
    163150
    164     if (psVec->type.type == PS_TYPE_PTR) {
    165         for(int i = 0; i < psVec->n; i++) {
    166             psFree(psVec->data.PTR[i]);
    167             psVec->data.PTR[i] = NULL;
    168         }
    169     }
    170 
    171151    psFree(psVec->data.V);
    172152}
    173 
    174 void psVectorElementFree(psVector *restrict psVec)
    175 {
    176 
    177     if(psVec == NULL) {
    178         return;
    179     }
    180 
    181     if (psVec->type.type != PS_TYPE_PTR) {
    182         psLogMsg(__func__,PS_LOG_WARN,"psVectorElementFree only operates on void* vectors");
    183         return;
    184     }
    185 
    186     for(int i = 0; i < psVec->n; i++) {
    187         psFree(psVec->data.PTR[i]);
    188         psVec->data.PTR[i] = NULL;
    189     }
    190 }
    191 
  • trunk/psLib/src/collections/psVector.h

    r1073 r1228  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-06-23 23:00:15 $
     13 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-07-15 22:18:02 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4949        psC32   *C32;                   ///< Single-precision complex data.
    5050        psC64   *C64;                   ///< Double-precision complex data.
    51         psPTR   *PTR;                   ///< Void pointers.
    5251        psPTR    V;                     ///< Pointer to data.
    5352    } data;                             ///< Union for data types.
     
    10099);
    101100
    102 /** Deallocate/Dereference elements of a void pointer vector.
    103  *
    104  * Uses psLib memory allocation functions to deallocate/dereference elements of a vector of void pointers.
    105  * This function does not free the vector elements unless the user provides a elemFree function
    106  * pointer. If the elemFree function pointer is NULL, the reference cound of the elements are decremented
    107  * without being freed.  The vector psVec is not freed, and its elements will all be set to NULL.
    108  *
    109  */
    110 void psVectorElementFree(
    111     psVector *restrict psVec    ///< Void pointer vector to destroy.
    112 );
    113 
    114101/// @}
    115102
  • trunk/psLib/src/mathtypes/psVector.c

    r1103 r1228  
    88 *  @author Ross Harman, MHPCC
    99 *
    10  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-06-26 00:24:30 $
     10 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-07-15 22:18:02 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    100100        elementSize = PSELEMTYPE_SIZEOF(elemType);
    101101        if(nalloc < in->n) {
    102             if (elemType == PS_TYPE_PTR) {
    103                 for (int i = nalloc; i < in->n; i++) {   // For reduction in vector size
    104                     psMemDecrRefCounter(in->data.PTR[i]);
    105                 }
    106             }
    107102            in->n = nalloc;
    108103        }
     
    139134
    140135
    141     // if vector of pointers, dereference old values.
    142     if (elemType == PS_TYPE_PTR) {
    143         for (int i = 0; i < in->n; i++) {   // For reduction in vector size
    144             psMemDecrRefCounter(in->data.PTR[i]);
    145             in->data.PTR[i] = NULL;
    146         }
    147     }
    148 
    149136    in->data.V = psRealloc(in->data.V,nalloc*PSELEMTYPE_SIZEOF(type));
    150137
     
    162149    }
    163150
    164     if (psVec->type.type == PS_TYPE_PTR) {
    165         for(int i = 0; i < psVec->n; i++) {
    166             psFree(psVec->data.PTR[i]);
    167             psVec->data.PTR[i] = NULL;
    168         }
    169     }
    170 
    171151    psFree(psVec->data.V);
    172152}
    173 
    174 void psVectorElementFree(psVector *restrict psVec)
    175 {
    176 
    177     if(psVec == NULL) {
    178         return;
    179     }
    180 
    181     if (psVec->type.type != PS_TYPE_PTR) {
    182         psLogMsg(__func__,PS_LOG_WARN,"psVectorElementFree only operates on void* vectors");
    183         return;
    184     }
    185 
    186     for(int i = 0; i < psVec->n; i++) {
    187         psFree(psVec->data.PTR[i]);
    188         psVec->data.PTR[i] = NULL;
    189     }
    190 }
    191 
  • trunk/psLib/src/mathtypes/psVector.h

    r1073 r1228  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-06-23 23:00:15 $
     13 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-07-15 22:18:02 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4949        psC32   *C32;                   ///< Single-precision complex data.
    5050        psC64   *C64;                   ///< Double-precision complex data.
    51         psPTR   *PTR;                   ///< Void pointers.
    5251        psPTR    V;                     ///< Pointer to data.
    5352    } data;                             ///< Union for data types.
     
    10099);
    101100
    102 /** Deallocate/Dereference elements of a void pointer vector.
    103  *
    104  * Uses psLib memory allocation functions to deallocate/dereference elements of a vector of void pointers.
    105  * This function does not free the vector elements unless the user provides a elemFree function
    106  * pointer. If the elemFree function pointer is NULL, the reference cound of the elements are decremented
    107  * without being freed.  The vector psVec is not freed, and its elements will all be set to NULL.
    108  *
    109  */
    110 void psVectorElementFree(
    111     psVector *restrict psVec    ///< Void pointer vector to destroy.
    112 );
    113 
    114101/// @}
    115102
  • trunk/psLib/src/pslib.h

    r1222 r1228  
    88 *  @author Eric Van Alst, MHPCC
    99 *   
    10  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2004-07-15 19:01:28 $
     10 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2004-07-15 22:18:02 $
    1212 *
    1313 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7373#include "psVector.h"
    7474
     75#include "psArray.h"
     76
    7577/// @defgroup Image Image Container
    7678/// @ingroup DataContainer
  • trunk/psLib/src/sysUtils/psHash.d

    r1111 r1228  
    11psHash.o psHash.d : psHash.c psHash.h ../collections/psList.h \
    2   ../collections/psCompare.h ../collections/psVector.h \
     2  ../collections/psCompare.h ../collections/psArray.h \
    33  ../collections/psType.h psMemory.h psString.h psTrace.h psAbort.h
  • trunk/psLib/src/types/psList.c

    r1193 r1228  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-07-08 01:05:00 $
     8 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-15 22:18:02 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    401401 * Convert a psList to/from a psVoidPtrArray
    402402 */
    403 psVector* psListToVector(psList* restrict list)
     403psArray* psListToArray(psList* restrict list)
    404404{
    405405    psListElem* ptr;
    406406    unsigned int n;
    407     psVector* restrict arr;
     407    psArray* restrict arr;
    408408
    409409    if (list == NULL) {
     
    412412
    413413    if (list->size > 0) {
    414         arr = psVectorAlloc(list->size, PS_TYPE_PTR);
    415     } else {
    416         arr = psVectorAlloc(1, PS_TYPE_PTR);
     414        arr = psArrayAlloc(list->size);
     415    } else {
     416        arr = psArrayAlloc(1);
    417417    }
    418418
     
    422422    n = list->size;
    423423    for (int i = 0; i < n; i++) {
    424         arr->data.PTR[i] = psMemIncrRefCounter(ptr->data);
     424        arr->data[i] = psMemIncrRefCounter(ptr->data);
    425425        ptr = ptr->next;
    426426    }
     
    429429}
    430430
    431 psList* psVectorToList(psVector* arr)
     431psList* psArrayToList(psArray* arr)
    432432{
    433433    unsigned int n;
     
    435435
    436436    if (arr == NULL) {
    437         return NULL;
    438     }
    439 
    440     if (arr->type.type != PS_TYPE_PTR) {
    441         psError(__func__,"Can not convert a non pointer-vector to a linked list.");
    442437        return NULL;
    443438    }
     
    446441    n = arr->n;
    447442    for (int i = 0; i < n; i++) {
    448         psListAdd(list,arr->data.PTR[i],PS_LIST_TAIL);
     443        psListAdd(list,arr->data[i],PS_LIST_TAIL);
    449444    }
    450445
     
    455450psList* psListSort(psList* list, psComparePtrFcn compare)
    456451{
    457     psVector* vector;
     452    psArray* arr;
    458453    if (list == NULL) {
    459454        return NULL;
     
    461456
    462457    // convert to indexable vector for use by qsort.
    463     vector = psListToVector(list);
     458    arr = psListToArray(list);
    464459    psFree(list);
    465460
    466     qsort(vector->data.V, vector->n, sizeof(void*),
    467           (int(*)(const void *, const void *))compare);
     461    arr = psArraySort(arr,compare);
    468462
    469463    // convert back to linked list
    470     list = psVectorToList(vector);
    471     psFree(vector);
     464    list = psArrayToList(arr);
     465    psFree(arr);
    472466
    473467    return list;
  • trunk/psLib/src/types/psList.h

    r1193 r1228  
    1010 *  @ingroup LinkedList
    1111 *
    12  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-08 01:05:00 $
     12 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-15 22:18:02 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2020
    2121#include "psCompare.h"
    22 #include "psVector.h"
     22#include "psArray.h"
    2323
    2424/** @addtogroup LinkedList
     
    156156/** Convert a linked list to an array
    157157 *
    158  *  @return psVector*   A new psVector populated with elements from the list,
     158 *  @return psArray*   A new psArray populated with elements from the list,
    159159 *                      or NULL if the given dlist parameter is NULL.
    160160 */
    161 psVector* psListToVector(
     161psArray* psListToArray(
    162162    psList *dlist                      ///< List to convert
    163163);
     
    165165/** Convert array to a doubly-linked list
    166166 *
    167  *  @return psList*     A new psList populated with elements formt the psVector,
     167 *  @return psList*     A new psList populated with elements formt the psArray,
    168168 *                      or NULL is the given arr parameter is NULL.
    169169 */
    170 psList* psVectorToList(
    171     psVector* arr                      ///< vector to convert
     170psList* psArrayToList(
     171    psArray* arr                      ///< vector to convert
    172172);
    173173
Note: See TracChangeset for help on using the changeset viewer.