IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1111


Ignore:
Timestamp:
Jun 28, 2004, 10:36:37 AM (22 years ago)
Author:
desonia
Message:

added pslistSort and cooresponding compare functions.

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

Legend:

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

    r1061 r1111  
    33##  Makefile:   collections
    44##
    5 ##  $Revision: 1.21 $  $Name: not supported by cvs2svn $
    6 ##  $Date: 2004-06-18 23:36:27 $
     5##  $Revision: 1.22 $  $Name: not supported by cvs2svn $
     6##  $Date: 2004-06-28 20:36:37 $
    77##
    88##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3535           psImage.o \
    3636           psList.o \
    37            psScalar.o
     37           psScalar.o \
     38           psCompare.o
    3839
    3940# Define PHONY target "all" which will make all the necessary items
  • trunk/psLib/src/collections/psList.c

    r1073 r1111  
    11/** @file psList.c
    22 *  @brief Support for doubly linked lists
    3  *  @ingroup DataContainers
     3 *  @ingroup LinkedList
    44 *
    55 *  @author Robert Lupton, Princeton University
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-23 23:00:15 $
     8 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-28 20:36:37 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    426426    arr->n = list->size;
    427427
    428 
    429428    ptr = list->head;
    430429    n = list->size;
     
    459458    return list;
    460459}
     460
     461
     462psList* psListSort(psList* list, psCompareFcn compare)
     463{
     464    psVector* vector;
     465    if (list == NULL) {
     466        return NULL;
     467    }
     468
     469    // convert to indexable vector for use by qsort.
     470    vector = psListToVector(list);
     471    psFree(list);
     472
     473    qsort(vector->data.V, vector->n, sizeof(void*),
     474          (int(*)(const void *, const void *))compare);
     475
     476    // convert back to linked list
     477    list = psVectorToList(vector);
     478
     479    return list;
     480}
  • trunk/psLib/src/collections/psList.d

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

    r1073 r1111  
    1010 *  @ingroup LinkedList
    1111 *
    12  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-06-23 23:00:15 $
     12 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-06-28 20:36:37 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#include <pthread.h>                   // we need a mutex to make this stuff thread safe.
    1919
     20#include "psCompare.h"
    2021#include "psVector.h"
    2122
     
    181182);
    182183
     184psList* psListSort(psList* list, psCompareFcn compare);
     185
    183186/// @} End of DataGroup Functions
    184187
    185188#endif
     189
  • trunk/psLib/src/sysUtils/psHash.d

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

    r1073 r1111  
    11/** @file psList.c
    22 *  @brief Support for doubly linked lists
    3  *  @ingroup DataContainers
     3 *  @ingroup LinkedList
    44 *
    55 *  @author Robert Lupton, Princeton University
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-23 23:00:15 $
     8 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-28 20:36:37 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    426426    arr->n = list->size;
    427427
    428 
    429428    ptr = list->head;
    430429    n = list->size;
     
    459458    return list;
    460459}
     460
     461
     462psList* psListSort(psList* list, psCompareFcn compare)
     463{
     464    psVector* vector;
     465    if (list == NULL) {
     466        return NULL;
     467    }
     468
     469    // convert to indexable vector for use by qsort.
     470    vector = psListToVector(list);
     471    psFree(list);
     472
     473    qsort(vector->data.V, vector->n, sizeof(void*),
     474          (int(*)(const void *, const void *))compare);
     475
     476    // convert back to linked list
     477    list = psVectorToList(vector);
     478
     479    return list;
     480}
  • trunk/psLib/src/types/psList.h

    r1073 r1111  
    1010 *  @ingroup LinkedList
    1111 *
    12  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-06-23 23:00:15 $
     12 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-06-28 20:36:37 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#include <pthread.h>                   // we need a mutex to make this stuff thread safe.
    1919
     20#include "psCompare.h"
    2021#include "psVector.h"
    2122
     
    181182);
    182183
     184psList* psListSort(psList* list, psCompareFcn compare);
     185
    183186/// @} End of DataGroup Functions
    184187
    185188#endif
     189
Note: See TracChangeset for help on using the changeset viewer.