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

psArray.h

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

Generated on Wed Jun 15 11:00:56 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.1