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.1.1.1 $ $Name:  $
00014  *  @date $Date: 2005/09/14 20:42:48 $
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<stdio.h>
00023 
00024 #include "psType.h"
00025 
00026 /// @addtogroup Vector
00027 /// @{
00028 
00029 /** An vector to support primitive types.
00030  *
00031  * Struct for maintaining an vector of frequently used primitive types.
00032  *
00033  */
00034 typedef struct
00035 {
00036     psMathType type;                       ///< Type of data.
00037     long n;                            ///< Number of elements in use.
00038     const long nalloc;                 ///< Total number of elements available.
00039     union {
00040         psU8* U8;                      ///< Unsigned 8-bit integer data.
00041         psU16* U16;                    ///< Unsigned 16-bit integer data.
00042         psU32* U32;                    ///< Unsigned 32-bit integer data.
00043         psU64* U64;                    ///< Unsigned 64-bit integer data.
00044         psS8* S8;                      ///< Signed 8-bit integer data.
00045         psS16* S16;                    ///< Signed 16-bit integer data.
00046         psS32* S32;                    ///< Signed 32-bit integer data.
00047         psS64* S64;                    ///< Signed 64-bit integer data.
00048         psF32* F32;                    ///< Single-precision float data.
00049         psF64* F64;                    ///< Double-precision float data.
00050         psC32* C32;                    ///< Single-precision complex data.
00051         psC64* C64;                    ///< Double-precision complex data.
00052     } data;
00053     void *lock;                        ///< Optional lock for thread safety.
00054 }
00055 psVector;
00056 
00057 /*****************************************************************************/
00058 
00059 /* FUNCTION PROTOTYPES                                                       */
00060 
00061 /*****************************************************************************/
00062 
00063 /** Checks the type of a particular pointer.
00064  *
00065  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00066  *
00067  *  @return bool:       True if the pointer matches a psVector structure, false otherwise.
00068  */
00069 bool psMemCheckVector(
00070     psPtr ptr                          ///< the pointer whose type to check
00071 )
00072 ;
00073 
00074 /** Allocate a vector.
00075  *
00076  *  Uses psLib memory allocation functions to create a vector collection of
00077  *  data as defined by the psType type.
00078  *
00079  * @return psVector*    Pointer to psVector.
00080  */
00081 psVector* psVectorAlloc(
00082     long nalloc,                       ///< Total number of elements to make available.
00083     psElemType type                    ///< Type of data to be held by vector.
00084 );
00085 
00086 /** Reallocate a vector.
00087  *
00088  *  Uses psLib memory allocation functions to reallocate a vector collection
00089  *  of data. The vector is reallocated according to the psType type member
00090  *  contained within the vector.
00091  *
00092  *  @return psVector*      Pointer to psVector.
00093  *
00094  */
00095 psVector* psVectorRealloc(
00096     psVector* vector,                  ///< Vector to reallocate.
00097     long nalloc                        ///< Total number of elements to make available.
00098 );
00099 
00100 /** Extend a vector's length.
00101  *
00102  *  Increments a vector's length, n, by the specified number of elements.
00103  *  If the allocated storage is less than the current vector's length plus
00104  *  twice the number of elements to be added, it is reallocated larger by
00105  *  a given amount.
00106  *
00107  *  @return psVector*      Pointer to the adjusted psVector
00108  */
00109 psVector *psVectorExtend(
00110     psVector *vector,                  ///< Vector to extend
00111     long delta,                        ///< Amount to expand allocation, if necessary
00112     long nExtend                       ///< Number of elements to add to vector length
00113 );
00114 
00115 /** Recycle a vector.
00116  *
00117  *  Uses psLib memory allocation functions to reallocate a vector collection
00118  *  of data. The vector is reallocated according to the psElemType type
00119  *  parameter.
00120  *
00121  * @return psVector*       Pointer to psVector.
00122  *
00123  */
00124 psVector* psVectorRecycle(
00125     psVector* vector,
00126     ///< Vector to recycle.  If NULL, a new vector is created.  No effort
00127     ///< taken to preserve the values.
00128 
00129     long nalloc,                       ///< Total number of elements to make available.
00130     psElemType type                    ///< the datatype of the returned vector
00131 );
00132 
00133 /** Copy a vector, converting types.
00134  *
00135  *  Performs a deep copy of the elements of one psVector to a new psVector,
00136  *  converting numeric types to a specified type.
00137  *
00138  * @return psVector*       Pointer to resulting psVector.
00139  *
00140  */
00141 psVector* psVectorCopy(
00142     psVector* output,                  ///< if non-NULL, a psVector to recycle
00143     const psVector* input,             ///< the vector to copy.
00144     psElemType type                    ///< the data type of the resulting psVector
00145 );
00146 
00147 /** Sort an array of floats.
00148  *
00149  *  Sorts an array of floats in ascending order.  This function is valid for
00150  *  all non-complex data types.
00151  *
00152  *  @return  psVector*     Pointer to sorted psVector.
00153  */
00154 psVector* psVectorSort(
00155     psVector* outVector,               ///< the output vector to recycle, or NULL if new vector desired.
00156     const psVector* inVector           ///< the vector to sort.
00157 );
00158 
00159 /** Creates an array of indices based on sort ordered of array.
00160  *
00161  *  Sorts a vector and creates an integer array holding indices of
00162  *  sorted float values based on pre-sort index positions.
00163  *
00164  *  @return  psVector*     vector of the indices of sort.
00165  */
00166 psVector* psVectorSortIndex(
00167     psVector* outVector,               ///< vector to recycle
00168     const psVector* inVector           ///< vector to sort
00169 );
00170 
00171 /** Creates a string from a psVector's values in the form "[x0,x1,x2]".
00172  *
00173  *  @return psPtr          a newly allocated string
00174  */
00175 char* psVectorToString(
00176     psVector* vector,                  ///< vector to create a string from
00177     int maxLength                      ///< the maximum length of the resulting string
00178 );
00179 
00180 /** Returns an element in the vector as a psF64 value
00181  *
00182  *  @return psF64          the value at specified position, or NAN if position is invalid.
00183  */
00184 psF64 p_psVectorGetElementF64(
00185     psVector* vector,                  ///< vector to retrieve element
00186     int position                       ///< the vector position to get
00187 );
00188 
00189 /** Print a vector to a stream
00190  *
00191  *  @return psBool          TRUE is successful, otherwise FALSE.
00192  */
00193 bool p_psVectorPrint (
00194     int fd,                            ///< output file descriptor
00195     psVector *a,                       ///< vector to print
00196     char *name                         ///< name of vector (for title)
00197 );
00198 
00199 /** Initializes the vector with the given value.
00200  *
00201  *  The input data is cast to match the vector datatype, allowing for integers to be preserved.
00202  *
00203  *  @return bool:       True if successful, otherwise false.
00204  */
00205 bool psVectorInit(
00206     psVector *image,                   ///< the vector to be initialized
00207     ...                                ///< Variable argument list for initialization
00208 );
00209 
00210 /// @}
00211 
00212 #endif // #ifndef PS_VECTOR_H

Generated on Wed Sep 14 10:42:48 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2