// Copyright (C) 2006 Fokko Beekhof // Email contact: Fokko.Beekhof@cui.unige.ch // The OMPTL library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifndef OMPTL_ALGORITHM #define OMPTL_ALGORITHM 1 #include #include "omptl" namespace omptl { template ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred, const unsigned P = _Pfunc::Pfunc()); template bool binary_search(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template bool binary_search(ForwardIterator first, ForwardIterator last, const T& value, const unsigned P = _Pfunc::Pfunc()); template OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); template BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result, const unsigned P = _Pfunc::Pfunc()); /* * Note: implementation assumes that * ::std::iterator_traits::difference_type(0) will * return a difference_type representing zero. */ template typename ::std::iterator_traits::difference_type count(InputIterator first, InputIterator last, const EqualityComparable& value, const unsigned P = _Pfunc::Pfunc()); template void count(InputIterator first, InputIterator last, const EqualityComparable& value, Size& n, const unsigned P = _Pfunc::Pfunc()); template typename InputIterator::difference_type count_if(InputIterator first, InputIterator last, Predicate pred, const unsigned P = _Pfunc::Pfunc()); template void count_if(InputIterator first, InputIterator last, Predicate pred, Size& n, const unsigned P = _Pfunc::Pfunc()); template bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred, const unsigned P = _Pfunc::Pfunc()); template bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, const unsigned P = _Pfunc::Pfunc()); template ::std::pair equal_range(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template ::std::pair equal_range(ForwardIterator first, ForwardIterator last, const T& value, const unsigned P = _Pfunc::Pfunc()); template void fill(ForwardIterator first, ForwardIterator last, const T& value, const unsigned P = _Pfunc::Pfunc()); template OutputIterator fill_n(OutputIterator first, Size n, const T& value, const unsigned P = _Pfunc::Pfunc()); /* * find suffers from a loss of efficiency when executed in parallel! */ template InputIterator find(InputIterator first, InputIterator last, const EqualityComparable& value, const unsigned P = _Pfunc::Pfunc()); /* * find_if suffers from a loss of efficiency when executed in parallel! */ template InputIterator find_if(InputIterator first, InputIterator last, Predicate pred, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate comp, const unsigned P = _Pfunc::Pfunc() ); template ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, const unsigned P = _Pfunc::Pfunc() ); /* * find_first_of suffers from a loss of efficiency when executed in parallel! */ template InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryPredicate comp, const unsigned P = _Pfunc::Pfunc()); template InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, const unsigned P = _Pfunc::Pfunc()); // Calls to UnaryFunction f must be completely independent template UnaryFunction for_each(InputIterator first, InputIterator last, UnaryFunction f, const unsigned P = _Pfunc::Pfunc()); // Not parallellized, Generator is explicitly allowed and expected to return // different results on subsequent calls. Order is therefor respected unless // the programmer explicitly accepts responsibility and calls par_generate. template void generate(ForwardIterator first, ForwardIterator last, Generator gen); template void par_generate(ForwardIterator first, ForwardIterator last, Generator gen, const unsigned P = _Pfunc::Pfunc()); template void push_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template void push_heap(RandomAccessIterator first, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); template inline void pop_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template inline void pop_heap(RandomAccessIterator first, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); template void make_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template void make_heap(RandomAccessIterator first, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); template void sort_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template void sort_heap(RandomAccessIterator first, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); // Warning: includes loses some efficiency in parallel. template bool includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template bool includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, const unsigned P = _Pfunc::Pfunc()); template bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate comp, const unsigned P = _Pfunc::Pfunc()); template bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& value, const unsigned P = _Pfunc::Pfunc()); template OutputIterator merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template OutputIterator merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator min_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator min_element(ForwardIterator first, ForwardIterator last, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator max_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator max_element(ForwardIterator first, ForwardIterator last, const unsigned P = _Pfunc::Pfunc()); template ::std::pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred, const unsigned P = _Pfunc::Pfunc()); template ::std::pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, const unsigned P = _Pfunc::Pfunc()); template void nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template void nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); template void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); template RandomAccessIterator partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template RandomAccessIterator partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator partition(ForwardIterator first, ForwardIterator last, Predicate pred, const unsigned P = _Pfunc::Pfunc()); template bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, const unsigned P = _Pfunc::Pfunc()); template bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred, const unsigned P = _Pfunc::Pfunc()); template void random_shuffle(RandomAccessIterator first, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); template void random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator &rgen, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator remove(ForwardIterator first, ForwardIterator last, const T& value, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate pred, const unsigned P = _Pfunc::Pfunc()); template OutputIterator remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value, const unsigned P = _Pfunc::Pfunc()); template OutputIterator remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const unsigned P = _Pfunc::Pfunc()); template void replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value, const unsigned P = _Pfunc::Pfunc()); template OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value, const unsigned P = _Pfunc::Pfunc()); template OutputIterator replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value, const unsigned P = _Pfunc::Pfunc()); template void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value, const unsigned P = _Pfunc::Pfunc()); template void reverse(BidirectionalIterator first, BidirectionalIterator last, const unsigned P = _Pfunc::Pfunc()); template OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator rotate( ForwardIterator first, ForwardIterator middle, ForwardIterator last, const unsigned P = _Pfunc::Pfunc()); template OutputIterator rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); // search suffers from a loss of efficiency when executed in parallel! template ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate binary_pred, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Integer count, const T& value, BinaryPredicate binary_pred, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Integer count, const T& value, const unsigned P = _Pfunc::Pfunc()); template OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); template OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); template OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); template OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); template void stable_sort(RandomAccessIterator first, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); template void stable_sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template void sort(RandomAccessIterator first, RandomAccessIterator last, const unsigned P = _Pfunc::Pfunc()); template void sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, const unsigned P = _Pfunc::Pfunc()); template OutputIterator transform(InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op, const unsigned P = _Pfunc::Pfunc()); template OutputIterator transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryFunction binary_op, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator unique(ForwardIterator first, ForwardIterator last, const unsigned P = _Pfunc::Pfunc()); template OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate binary_pred, const unsigned P = _Pfunc::Pfunc()); template OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp, const unsigned P = _Pfunc::Pfunc()); template ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value, const unsigned P = _Pfunc::Pfunc()); } // namespace omptl #ifdef _OPENMP #include "omptl_algorithm_par.h" #else #include "omptl_algorithm_ser.h" #endif #endif /* OMPTL_ALGORITHM */