Embedded Multicore Building Blocks V1.0.0
quick_sort.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_ALGORITHMS_QUICK_SORT_H_
28 #define EMBB_ALGORITHMS_QUICK_SORT_H_
29 
30 #include <functional>
31 #include <embb/mtapi/job.h>
32 #include <embb/mtapi/execution_policy.h>
33 
34 namespace embb {
35 namespace algorithms {
36 
42 #ifdef DOXYGEN
43 
69 template <typename RAI, typename ComparisonFunction>
70 void QuickSort(
71  RAI first,
73  RAI last,
76  ComparisonFunction comparison
77  = std::less<typename std::iterator_traits<RAI>::value_type>(),
84  size_t block_size = 0
93  );
94 
95 #else // DOXYGEN
96 
100 template <typename RAI>
101 void QuickSort(
102  RAI first,
103  RAI last,
104  embb::mtapi::Job comparison,
105  const embb::mtapi::ExecutionPolicy& policy,
106  size_t block_size
107  );
108 
112 template <typename RAI, typename ComparisonFunction>
113 void QuickSort(
114  RAI first,
115  RAI last,
116  ComparisonFunction comparison,
117  const embb::mtapi::ExecutionPolicy& policy,
118  size_t block_size
119  );
120 
124 template <typename RAI>
125 void QuickSort(
126  RAI first,
127  RAI last
128  ) {
129  QuickSort(first, last,
130  std::less<typename std::iterator_traits<RAI>::value_type>(),
132 }
133 
137 template <typename RAI, typename ComparisonFunction>
138 void QuickSort(
139  RAI first,
140  RAI last,
141  ComparisonFunction comparison
142  ) {
143  QuickSort(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
144 }
145 
149 template <typename RAI, typename ComparisonFunction>
150 void QuickSort(
151  RAI first,
152  RAI last,
153  ComparisonFunction comparison,
154  const embb::mtapi::ExecutionPolicy& policy
155  ) {
156  QuickSort(first, last, comparison, policy, 0);
157 }
158 
159 #endif // else DOXYGEN
160 
165 } // namespace algorithms
166 } // namespace embb
167 #include<embb/algorithms/internal/quick_sort-inl.h>
168 
169 #endif // EMBB_ALGORITHMS_QUICK_SORT_H_
Definition: lock_free_mpmc_queue.h:40
void QuickSort(RAI first, RAI last, ComparisonFunction comparison=std::less< typename std::iterator_traits< RAI >::value_type >(), const embb::mtapi::ExecutionPolicy &policy=embb::mtapi::ExecutionPolicy(), size_t block_size=0)
Sorts a range of elements using a parallel quick sort algorithm.
Represents a collection of Actions.
Definition: job.h:41
Describes the execution policy of a parallel algorithm.
Definition: execution_policy.h:48