Embedded Multicore Building Blocks V1.0.0
count.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_COUNT_H_
28 #define EMBB_ALGORITHMS_COUNT_H_
29 
30 #include <embb/mtapi/job.h>
31 #include <embb/mtapi/execution_policy.h>
32 #include <iterator>
33 
34 namespace embb {
35 namespace algorithms {
36 
44 #ifdef DOXYGEN
45 
67 template<typename RAI, typename ValueType>
68 typename std::iterator_traits<RAI>::difference_type Count(
69  RAI first,
71  RAI last,
74  const ValueType& value,
79  size_t block_size = 0
86  );
87 
113 template<typename RAI, typename ComparisonFunction>
114 typename std::iterator_traits<RAI>::difference_type CountIf(
115  RAI first,
120  ComparisonFunction comparison,
125  size_t block_size = 0
132  );
133 
134 #else // DOXYGEN
135 
139 template<typename RAI, typename ValueType>
140 typename std::iterator_traits<RAI>::difference_type Count(
141  RAI first,
142  RAI last,
143  const ValueType& value,
144  const embb::mtapi::ExecutionPolicy& policy,
145  size_t block_size
146  );
147 
151 template<typename RAI, typename ValueType>
152 typename std::iterator_traits<RAI>::difference_type Count(
153  RAI first,
154  RAI last,
155  const ValueType& value
156  ) {
157  return Count(first, last, value, embb::mtapi::ExecutionPolicy(), 0);
158 }
159 
163 template<typename RAI, typename ValueType>
164 typename std::iterator_traits<RAI>::difference_type Count(
165  RAI first,
166  RAI last,
167  const ValueType& value,
168  const embb::mtapi::ExecutionPolicy& policy
169  ) {
170  return Count(first, last, value, policy, 0);
171 }
172 
176 template<typename RAI>
177 typename std::iterator_traits<RAI>::difference_type CountIf(
178  RAI first,
179  RAI last,
180  embb::mtapi::Job comparison,
181  const embb::mtapi::ExecutionPolicy& policy,
182  size_t block_size
183  );
184 
188 template<typename RAI, typename ComparisonFunction>
189 typename std::iterator_traits<RAI>::difference_type CountIf(
190  RAI first,
191  RAI last,
192  ComparisonFunction comparison,
193  const embb::mtapi::ExecutionPolicy& policy,
194  size_t block_size
195  );
196 
200 template<typename RAI, typename ComparisonFunction>
201 typename std::iterator_traits<RAI>::difference_type CountIf(
202  RAI first,
203  RAI last,
204  ComparisonFunction comparison
205  ) {
206  return CountIf(first, last, comparison, embb::mtapi::ExecutionPolicy(), 0);
207 }
208 
212 template<typename RAI, typename ComparisonFunction>
213 typename std::iterator_traits<RAI>::difference_type CountIf(
214  RAI first,
215  RAI last,
216  ComparisonFunction comparison,
217  const embb::mtapi::ExecutionPolicy& policy
218  ) {
219  return CountIf(first, last, comparison, policy, 0);
220 }
221 
222 #endif // else DOXYGEN
223 
228 } // namespace algorithms
229 } // namespace embb
230 
231 #include <embb/algorithms/internal/count-inl.h>
232 
233 #endif // EMBB_ALGORITHMS_COUNT_H_
Definition: lock_free_mpmc_queue.h:40
std::iterator_traits< RAI >::difference_type Count(RAI first, RAI last, const ValueType &value, const embb::mtapi::ExecutionPolicy &policy=embb::mtapi::ExecutionPolicy(), size_t block_size=0)
Counts in parallel the number of elements in a range that are equal to the specified value...
Represents a collection of Actions.
Definition: job.h:41
Describes the execution policy of a parallel algorithm.
Definition: execution_policy.h:48
std::iterator_traits< RAI >::difference_type CountIf(RAI first, ComparisonFunction comparison, const embb::mtapi::ExecutionPolicy &policy=embb::mtapi::ExecutionPolicy(), size_t block_size=0)
Counts in parallel the number of elements in a range for which the comparison function returns true...