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