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

psArray.h

Go to the documentation of this file.
00001 /** @file  psArray.h
00002  *
00003  *  @brief Contains basic array definitions and operations
00004  *
00005  *  This file defines the basic type for a array struct and functions useful
00006  *  in manupulating arrays.
00007  *
00008  *  @ingroup Array
00009  *
00010  *  @author Robert DeSonia, MHPCC
00011  *  @author Ross Harman, MHPCC
00012  *
00013  *  @version $Revision: 1.36 $ $Name: rel12 $
00014  *  @date $Date: 2006/02/28 02:53:03 $
00015  *
00016  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00017  */
00018 
00019 #ifndef PS_ARRAY_H
00020 #define PS_ARRAY_H
00021 
00022 #include "psType.h"
00023 #include "psCompare.h"
00024 
00025 /// @addtogroup Array
00026 /// @{
00027 
00028 /** An array to support primitive types.
00029  *
00030  * Struct for maintaining an array of frequently used primitive types.
00031  *
00032  */
00033 typedef struct
00034 {
00035     long n;                            ///< Number of elements in use.
00036     const long nalloc;                 ///< Total number of elements available.
00037     psPtr* data;                       ///< An Array of pointer elements
00038     void *lock;                        ///< Optional lock for thread safety
00039 }
00040 psArray;
00041 
00042 #define P_PSARRAY_SET_NALLOC(vec,n) *(long*)&vec->nalloc = n
00043 
00044         /*****************************************************************************/
00045 
00046         /* FUNCTION PROTOTYPES                                                       */
00047 
00048         /*****************************************************************************/
00049 
00050         /** Checks the type of a particular pointer.
00051          *
00052          *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00053          *
00054          *  @return bool:       True if the pointer matches a psArray structure, false otherwise.
00055          */
00056         bool psMemCheckArray(
00057             psPtr ptr                          ///< the pointer whose type to check
00058         )
00059         ;
00060 
00061 
00062 /** Allocate an array.
00063  *
00064  * Uses psLib memory allocation functions to create an array collection of
00065  * data
00066  *
00067  * @return psArray* : Pointer to psArray.
00068  *
00069  */
00070 psArray* psArrayAlloc(
00071     long nalloc                        ///< Total number of elements to make available.
00072 );
00073 
00074 /** Reallocate an array.
00075  *
00076  * Uses psLib memory allocation functions to reallocate an array collection
00077  * of data.
00078  *
00079  * @return psArray* : Pointer to psArray.
00080  *
00081  */
00082 psArray* psArrayRealloc(
00083     psArray* array,                    ///< array to reallocate.
00084     long nalloc                        ///< Total number of elements to make available.
00085 );
00086 
00087 /** Add an element to the end the array, expanding the array storage if
00088  *  necessary.
00089  *
00090  *  @return psArray*        The array with the element added
00091  */
00092 psArray* psArrayAdd(
00093     psArray* array,                    ///< array to operate on
00094     long delta,
00095     ///< the amount to expand array, if necessary.  If less than one, 10 will be used.
00096     psPtr data                         ///< the data pointer to add to psArray
00097 );
00098 
00099 /** Remove an element from the array
00100  *
00101  *  Finds and removes the specified data pointer from the list.
00102  *
00103  * @return bool:  TRUE if the specified data pointer was found and removed,
00104  *                otherwise FALSE.
00105  *
00106  */
00107 bool psArrayRemove(
00108     psArray* array,                    ///< array to operate on
00109     const psPtr data                   ///< the data pointer to remove from psArray
00110 );
00111 
00112 /** Deallocate/Dereference elements of an array.
00113  *
00114  * Uses psLib memory allocation functions to deallocate/dereference elements
00115  * of a array of void pointers.  The array psArr is not freed, and its elements
00116  * will all be set to NULL.
00117  *
00118  */
00119 void psArrayElementsFree(
00120     psArray* array                     ///< Void pointer array to destroy.
00121 );
00122 
00123 /** Sort the array according to an external compare function.
00124  *
00125  *  Sorts an array via the specification of a comparison function
00126  *  to specify how the objects on the array should be sorted.
00127  *
00128  *  The comparison function must return an integer less than, equal to, or
00129  *  greater than zero if the first argument is considered to be respectively
00130  *  less than, equal to, or greater than the second.
00131  *
00132  *  If two members compare as equal, their order in the sorted array is
00133  *  undefined.
00134  *
00135  *  @return psArray* The sorted array.
00136  */
00137 psArray* psArraySort(
00138     psArray* array,                       ///< input array to sort.
00139     psComparePtrFunc func                 ///< the compare function
00140 );
00141 
00142 /** Set an element in the array.  If the current element is non-NULL, the old
00143  *  element is freed.
00144  *
00145  *  @return psBool  TRUE if the element was set successfully, otherwise FALSE
00146  */
00147 bool psArraySet(
00148     psArray* array,                    ///< input array to set element in
00149     long position,                     ///< the element position to set
00150     psPtr data                         ///< the value to set it to
00151 );
00152 
00153 /** Get an element from the array.
00154  *
00155  *  @return void*   the element at given position.
00156  */
00157 psPtr psArrayGet(
00158     const psArray* array,              ///< input array to get element from
00159     long position                      ///< the element position to get
00160 );
00161 
00162 /** Get the number of elements in use from a specified psArray. (array.n)
00163  *
00164  *  @return long:       The number of elements in use.
00165  */
00166 long psArrayLength(
00167     const psArray *array               ///< input psArray
00168 );
00169 
00170 /// @}
00171 
00172 #endif // #ifndef PS_ARRAY_H

Generated on Mon Jul 3 14:13:44 2006 for Pan-STARRS Foundation Library by  doxygen 1.4.4