Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phQuicksort.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008     
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU Lesser General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019     GNU Lesser General Public License for more details.
00020 
00021     You should have received a copy of the GNU Lesser General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 #ifndef _PHQUICKSORT_H
00027 #define _PHQUICKSORT_H
00028 
00029 #include <phStandard.h>
00030 #include <phStdint.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00046 /* ---------------------------------------------------------------------- */
00047 /* Types */
00048 typedef int32_t (*ph_qs_compare_fn)(const void *_one, const void *_two);
00049 
00050 /* ---------------------------------------------------------------------- */
00051 /* Prototypes */
00056 PHAPI(int32_t) ph_quicksort_partition(const void       *arr,
00057                                       const int32_t     low,
00058                                       const int32_t     high,
00059                                       const uint32_t    size,
00060                                       uint8_t          *tempptr,
00061                                       ph_qs_compare_fn  compare );
00062                                             
00067 PHAPI(void) ph_quicksort_recursive( const void         *arr, 
00068                                     const int32_t       low, 
00069                                     const int32_t       high,
00070                                     const uint32_t      size,
00071                                     uint8_t            *tempptr,
00072                                     ph_qs_compare_fn    compare );
00073                                 
00078 PHAPI(void) ph_quicksort_iterative( const void         *arr, 
00079                                     const int32_t       low, 
00080                                     const int32_t       high,
00081                                     const uint32_t      size,
00082                                     uint8_t            *tempptr,
00083                                     ph_qs_compare_fn    compare );
00084                                     
00085 /* ---------------------------------------------------------------------- */
00086 /* Sort a uint32_t array */
00091 PHAPI(int32_t) ph_qs_sort_uint32_t      ( const uint32_t  nelements, 
00092                                           uint32_t       *array,
00093                                           const uint32_t  method        );
00094 
00099 PHAPI(int32_t) ph_qs_compare_uint32_t   ( const void     *_one, 
00100                                           const void     *_two          );
00101 
00106 PHAPI(int32_t) ph_qs_randomfill_uint32_t( const uint32_t  nelements,
00107                                           uint32_t       *array,
00108                                           const uint32_t  maxval        );
00109 
00114 PHAPI(int32_t) ph_qs_print_uint32_t     ( const uint32_t  nelements, 
00115                                           const uint32_t *array         );
00116 
00121 PHAPI(int32_t) ph_qs_verify_uint32_t    ( const uint32_t  nelements, 
00122                                           const uint32_t *array         );
00123 
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127 
00128 /* ---------------------------------------------------------------------- */
00129 /* Defines */
00130 #define ph_qsMemswap( ptrone, ptrtwo, tempptr, size )   \
00131     do {                                                \
00132         if ((ptrone != ptrtwo) &&                       \
00133             (ptrtwo != tempptr) &&                      \
00134             (tempptr != ptrone))                        \
00135         {                                               \
00136             phMemcpy(tempptr,ptrone,size);              \
00137             phMemcpy(ptrone,ptrtwo,size);               \
00138             phMemcpy(ptrtwo,tempptr,size);              \
00139         }                                               \
00140     } while (0);
00141 
00142 #endif /* _PHQUICKSORT_H */
00143 #if 0
00144         else                                            \
00145         {                                               \
00146             printf("warning: ");                        \
00147             if (ptrone == ptrtwo)                       \
00148                 printf("ptrone == ptrtwo ");            \
00149             if (ptrtwo == tempptr)                      \
00150                 printf("ptrtwo == tempptr ");           \
00151             if (ptrone == tempptr)                      \
00152                 printf("ptrone == tempptr");            \
00153         }                                               
00154 #endif
00155  /* end \addtogroup Quicksort */ /* end \addtogroup Algorithms */




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:02 2007 for phission by  doxygen 1.4.4