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.1.1.1 $ $Name:  $
00014  *  @date $Date: 2005/10/14 00:32:52 $
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 /*****************************************************************************/
00043 
00044 /* FUNCTION PROTOTYPES                                                       */
00045 
00046 /*****************************************************************************/
00047 
00048 /** Checks the type of a particular pointer.
00049  *
00050  *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
00051  *
00052  *  @return bool:       True if the pointer matches a psArray structure, false otherwise.
00053  */
00054 bool psMemCheckArray(
00055     psPtr ptr                          ///< the pointer whose type to check
00056 )
00057 ;
00058 
00059 
00060 /** Allocate an array.
00061  *
00062  * Uses psLib memory allocation functions to create an array collection of
00063  * data
00064  *
00065  * @return psArray* : Pointer to psArray.
00066  *
00067  */
00068 psArray* psArrayAlloc(
00069     long nalloc                        ///< Total number of elements to make available.
00070 );
00071 
00072 /** Reallocate an array.
00073  *
00074  * Uses psLib memory allocation functions to reallocate an array collection
00075  * of data.
00076  *
00077  * @return psArray* : Pointer to psArray.
00078  *
00079  */
00080 psArray* psArrayRealloc(
00081     psArray* array,                    ///< array to reallocate.
00082     long nalloc                        ///< Total number of elements to make available.
00083 );
00084 
00085 /** Add an element to the end the array, expanding the array storage if
00086  *  necessary.
00087  *
00088  *  @return psArray*        The array with the element added
00089  */
00090 psArray* psArrayAdd(
00091     psArray* array,                    ///< array to operate on
00092     long delta,
00093     ///< the amount to expand array, if necessary.  If less than one, 10 will be used.
00094     psPtr data                         ///< the data pointer to add to psArray
00095 );
00096 
00097 /** Remove an element from the array
00098  *
00099  *  Finds and removes the specified data pointer from the list.
00100  *
00101  * @return bool:  TRUE if the specified data pointer was found and removed,
00102  *                otherwise FALSE.
00103  *
00104  */
00105 bool psArrayRemove(
00106     psArray* array,                    ///< array to operate on
00107     const psPtr data                   ///< the data pointer to remove from psArray
00108 );
00109 
00110 /** Deallocate/Dereference elements of an array.
00111  *
00112  * Uses psLib memory allocation functions to deallocate/dereference elements
00113  * of a array of void pointers.  The array psArr is not freed, and its elements
00114  * will all be set to NULL.
00115  *
00116  */
00117 void psArrayElementsFree(
00118     psArray* psArr                     ///< Void pointer array to destroy.
00119 );
00120 
00121 /** Sort the array according to an external compare function.
00122  *
00123  *  Sorts an array via the specification of a comparison function
00124  *  to specify how the objects on the array should be sorted.
00125  *
00126  *  The comparison function must return an integer less than, equal to, or
00127  *  greater than zero if the first argument is considered to be respectively
00128  *  less than, equal to, or greater than the second.
00129  *
00130  *  If two members compare as equal, their order in the sorted array is
00131  *  undefined.
00132  *
00133  *  @return psArray* The sorted array.
00134  */
00135 psArray* psArraySort(
00136     psArray* array,                       ///< input array to sort.
00137     psComparePtrFunc func                 ///< the compare function
00138 );
00139 
00140 /** Set an element in the array.  If the current element is non-NULL, the old
00141  *  element is freed.
00142  *
00143  *  @return psBool  TRUE if the element was set successfully, otherwise FALSE
00144  */
00145 bool psArraySet(
00146     psArray* array,                    ///< input array to set element in
00147     long position,                     ///< the element position to set
00148     psPtr data                         ///< the value to set it to
00149 );
00150 
00151 /** Get an element from the array.
00152  *
00153  *  @return void*   the element at given position.
00154  */
00155 psPtr psArrayGet(
00156     const psArray* array,              ///< input array to get element from
00157     long position                      ///< the element position to get
00158 );
00159 
00160 /// @}
00161 
00162 #endif // #ifndef PS_ARRAY_H

Generated on Thu Oct 13 14:32:52 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2