00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _GLIBCXX_PARALLEL_SORT_H
00039 #define _GLIBCXX_PARALLEL_SORT_H 1
00040
00041 #include <parallel/basic_iterator.h>
00042 #include <parallel/features.h>
00043 #include <parallel/parallel.h>
00044
00045 #if _GLIBCXX_ASSERTIONS
00046 #include <parallel/checkers.h>
00047 #endif
00048
00049 #if _GLIBCXX_MERGESORT
00050 #include <parallel/multiway_mergesort.h>
00051 #endif
00052
00053 #if _GLIBCXX_QUICKSORT
00054 #include <parallel/quicksort.h>
00055 #endif
00056
00057 #if _GLIBCXX_BAL_QUICKSORT
00058 #include <parallel/balanced_quicksort.h>
00059 #endif
00060
00061 namespace __gnu_parallel
00062 {
00063
00064
00065
00066
00067
00068
00069
00070
00071 template<typename RandomAccessIterator, typename Comparator>
00072 inline void
00073 parallel_sort(RandomAccessIterator begin, RandomAccessIterator end,
00074 Comparator comp, bool stable)
00075 {
00076 _GLIBCXX_CALL(end - begin)
00077 typedef std::iterator_traits<RandomAccessIterator> traits_type;
00078 typedef typename traits_type::value_type value_type;
00079 typedef typename traits_type::difference_type difference_type;
00080
00081 if (begin != end)
00082 {
00083 difference_type n = end - begin;
00084
00085 if (false) ;
00086 #if _GLIBCXX_MERGESORT
00087 else if (stable || _Settings::get().sort_algorithm == MWMS)
00088 parallel_sort_mwms(begin, end, comp, n, get_max_threads(), stable);
00089 #endif
00090 #if _GLIBCXX_QUICKSORT
00091 else if (!stable && _Settings::get().sort_algorithm == QS)
00092 parallel_sort_qs(begin, end, comp, n, get_max_threads());
00093 #endif
00094 #if _GLIBCXX_BAL_QUICKSORT
00095 else if (!stable && _Settings::get().sort_algorithm == QS_BALANCED)
00096 parallel_sort_qsb(begin, end, comp, n, get_max_threads());
00097 #endif
00098 else
00099 __gnu_sequential::sort(begin, end, comp);
00100 }
00101 }
00102 }
00103
00104 #endif