Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psVector.h

Go to the documentation of this file.
00001 /** @file  psVector.h
00002  *
00003  *  @brief Contains basic vector definitions and operations
00004  *
00005  *  This file defines the basic type for a vector struct and functions useful
00006  *  in manupulating vectors.
00007  *
00008  *  @ingroup Vector
00009  *
00010  *  @author Robert DeSonia, MHPCC
00011  *  @author Ross Harman, MHPCC
00012  *
00013  *  @version $Revision: 1.30 $ $Name: rel5_0 $
00014  *  @date $Date: 2005/03/22 21:52:49 $
00015  *
00016  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00017  */
00018 
00019 #ifndef PS_VECTOR_H
00020 #define PS_VECTOR_H
00021 
00022 #include "psType.h"
00023 
00024 /// @addtogroup Vector
00025 /// @{
00026 
00027 /** An vector to support primitive types.
00028  *
00029  * Struct for maintaining an vector of frequently used primitive types.
00030  *
00031  */
00032 typedef struct
00033 {
00034     psType type;                ///< Type of data.
00035     psU32 nalloc;        ///< Total number of elements available.
00036     psU32 n;             ///< Number of elements in use.
00037 
00038     union {
00039         psU8* U8;               ///< Unsigned 8-bit integer data.
00040         psU16* U16;             ///< Unsigned 16-bit integer data.
00041         psU32* U32;             ///< Unsigned 32-bit integer data.
00042         psU64* U64;             ///< Unsigned 64-bit integer data.
00043         psS8* S8;               ///< Signed 8-bit integer data.
00044         psS16* S16;             ///< Signed 16-bit integer data.
00045         psS32* S32;             ///< Signed 32-bit integer data.
00046         psS64* S64;             ///< Signed 64-bit integer data.
00047         psF32* F32;             ///< Single-precision float data.
00048         psF64* F64;             ///< Double-precision float data.
00049         psC32* C32;             ///< Single-precision complex data.
00050         psC64* C64;             ///< Double-precision complex data.
00051     } data;                     ///< Union for data types.
00052 }
00053 psVector;
00054 
00055 /*****************************************************************************/
00056 
00057 /* FUNCTION PROTOTYPES                                                       */
00058 
00059 /*****************************************************************************/
00060 
00061 
00062 /** Allocate a vector.
00063  *
00064  *  Uses psLib memory allocation functions to create a vector collection of
00065  *  data as defined by the psType type.
00066  *
00067  * @return psVector*    Pointer to psVector.
00068  */
00069 psVector* psVectorAlloc(
00070     psU32 nalloc,               ///< Total number of elements to make available.
00071     psElemType dataType                ///< Type of data to be held by vector.
00072 );
00073 
00074 /** Reallocate a vector.
00075  *
00076  *  Uses psLib memory allocation functions to reallocate a vector collection
00077  *  of data. The vector is reallocated according to the psType type member
00078  *  contained within the vector.
00079  *
00080  *  @return psVector*      Pointer to psVector.
00081  *
00082  */
00083 psVector* psVectorRealloc(
00084     psVector* psVec,                   ///< Vector to reallocate.
00085     psU32 nalloc                       ///< Total number of elements to make available.
00086 );
00087 
00088 /** Recycle a vector.
00089  *
00090  *  Uses psLib memory allocation functions to reallocate a vector collection
00091  *  of data. The vector is reallocated according to the psElemType type
00092  *  parameter.
00093  *
00094  * @return psVector*       Pointer to psVector.
00095  *
00096  */
00097 psVector* psVectorRecycle(
00098     psVector* psVec,
00099     ///< Vector to recycle.  If NULL, a new vector is created.  No effort
00100     ///< taken to preserve the values.
00101 
00102     psU32 nalloc,                      ///< Total number of elements to make available.
00103     psElemType type                    ///< the datatype of the returned vector
00104 );
00105 
00106 /** Copy a vector, converting types.
00107  *
00108  *  Performs a deep copy of the elements of one psVector to a new psVector,
00109  *  converting numeric types to a specified type.
00110  *
00111  * @return psVector*       Pointer to resulting psVector.
00112  *
00113  */
00114 psVector* psVectorCopy(
00115     psVector* out,                     ///< if non-NULL, a psVector to recycle
00116     const psVector* in,                ///< the vector to copy.
00117     psElemType type                    ///< the data type of the resulting psVector
00118 );
00119 
00120 /** Sort an array of floats.
00121  *
00122  *  Sorts an array of floats in ascending order.  This function is valid for
00123  *  all non-complex data types.
00124  *
00125  *  @return  psVector*     Pointer to sorted psVector.
00126  */
00127 psVector* psVectorSort(
00128     psVector* outVector,               ///< the output vector to recycle, or NULL if new vector desired.
00129     const psVector* inVector           ///< the vector to sort.
00130 );
00131 
00132 /** Creates an array of indices based on sort ordered of array.
00133  *
00134  *  Sorts a vector and creates an integer array holding indices of
00135  *  sorted float values based on pre-sort index positions.
00136  *
00137  *  @return  psVector*     vector of the indices of sort.
00138  */
00139 psVector* psVectorSortIndex(
00140     psVector* outVector,               ///< vector to recycle
00141     const psVector* inVector           ///< vector to sort
00142 );
00143 
00144 /** Creates a string from a psVector's values in the form "[x0,x1,x2]".
00145  *
00146  *  @return psPtr          a newly allocated string
00147  */
00148 char* psVectorToString(
00149     psVector* vector,                  ///< vector to create a string from
00150     int maxLength                      ///< the maximum length of the resulting string
00151 );
00152 
00153 /** Returns an element in the vector as a psF64 value
00154  *
00155  *  @return psF64          the value at specified position, or NAN if position is invalid.
00156  */
00157 psF64 p_psVectorGetElementF64(
00158     psVector* vector,                  ///< vector to retrieve element
00159     int position                       ///< the vector position to get
00160 );
00161 
00162 
00163 /// @}
00164 
00165 #endif

Generated on Mon Apr 4 18:24:45 2005 for Pan-STARRS Foundation Library by  doxygen 1.3.9.1