]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/parallel/sort.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / parallel / sort.h
1 // -*- C++ -*-
2
3 // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
10
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
20
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction.  Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License.  This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
30
31 /** @file parallel/sort.h
32  *  @brief Parallel sorting algorithm switch.
33  *  This file is a GNU parallel extension to the Standard C++ Library.
34  */
35
36 // Written by Johannes Singler.
37
38 #ifndef _GLIBCXX_PARALLEL_SORT_H
39 #define _GLIBCXX_PARALLEL_SORT_H 1
40
41 #include <parallel/basic_iterator.h>
42 #include <parallel/features.h>
43 #include <parallel/parallel.h>
44
45 #if _GLIBCXX_ASSERTIONS
46 #include <parallel/checkers.h>
47 #endif
48
49 #if _GLIBCXX_MERGESORT
50 #include <parallel/multiway_mergesort.h>
51 #endif
52
53 #if _GLIBCXX_QUICKSORT
54 #include <parallel/quicksort.h>
55 #endif
56
57 #if _GLIBCXX_BAL_QUICKSORT
58 #include <parallel/balanced_quicksort.h>
59 #endif
60
61 namespace __gnu_parallel
62 {
63   /** 
64    *  @brief Choose a parallel sorting algorithm.
65    *  @param begin Begin iterator of input sequence.
66    *  @param end End iterator of input sequence.
67    *  @param comp Comparator.
68    *  @param stable Sort stable.
69    *  @callgraph 
70    */
71   template<typename RandomAccessIterator, typename Comparator>
72     inline void
73     parallel_sort(RandomAccessIterator begin, RandomAccessIterator end,
74                   Comparator comp, bool stable)
75     {
76       _GLIBCXX_CALL(end - begin)
77       typedef std::iterator_traits<RandomAccessIterator> traits_type;
78       typedef typename traits_type::value_type value_type;
79       typedef typename traits_type::difference_type difference_type;
80
81       if (begin != end)
82       {
83         difference_type n = end - begin;
84
85         if (false) ;
86 #if _GLIBCXX_MERGESORT
87         else if (stable)
88           {
89             if(_Settings::get().sort_splitting == EXACT)
90               parallel_sort_mwms<true, true>
91                 (begin, end, comp, get_max_threads());
92             else
93               parallel_sort_mwms<true, false>
94                 (begin, end, comp, get_max_threads());
95           }
96         else if (_Settings::get().sort_algorithm == MWMS)
97           {
98             if(_Settings::get().sort_splitting == EXACT)
99               parallel_sort_mwms<false, true>
100                 (begin, end, comp, get_max_threads());
101             else
102               parallel_sort_mwms<false, false>
103                 (begin, end, comp, get_max_threads());
104           }
105 #endif
106 #if _GLIBCXX_QUICKSORT
107         else if (!stable && _Settings::get().sort_algorithm == QS)
108           parallel_sort_qs(begin, end, comp, n, get_max_threads());
109 #endif
110 #if _GLIBCXX_BAL_QUICKSORT
111         else if (!stable && _Settings::get().sort_algorithm == QS_BALANCED)
112           parallel_sort_qsb(begin, end, comp, n, get_max_threads());
113 #endif
114         else if(stable)
115           __gnu_sequential::stable_sort(begin, end, comp);
116         else
117           __gnu_sequential::sort(begin, end, comp);
118       }
119     }
120 } // end namespace __gnu_parallel
121
122 #endif