Commit 531898c3 by Paolo Carlini Committed by Paolo Carlini

iterator.h: Reformat to 80 columns; adjust some inline specifiers.

2008-01-09  Paolo Carlini  <pcarlini@suse.de>

	* include/parallel/iterator.h: Reformat to 80 columns; adjust some
	inline specifiers.
	* include/parallel/find_selectors.h: Likewise.
	* include/parallel/losertree.h: Likewise.
	* include/parallel/list_partition.h: Likewise.
	* include/parallel/for_each.h: Likewise.
	* include/parallel/multiseq_selection.h: Likewise.
	* include/parallel/algorithmfwd.h: Likewise.
	* include/parallel/for_each_selectors.h: Likewise.
	* include/parallel/balanced_quicksort.h: Likewise.
	* include/parallel/merge.h: Likewise.
	* include/parallel/algobase.h: Likewise.
	* include/parallel/find.h: Likewise.
	* include/parallel/algo.h: Likewise.
	* include/parallel/checkers.h: Likewise.

From-SVN: r131431
parent c3e203cf
2008-01-09 Paolo Carlini <pcarlini@suse.de>
* include/parallel/iterator.h: Reformat to 80 columns; adjust some
inline specifiers.
* include/parallel/find_selectors.h: Likewise.
* include/parallel/losertree.h: Likewise.
* include/parallel/list_partition.h: Likewise.
* include/parallel/for_each.h: Likewise.
* include/parallel/multiseq_selection.h: Likewise.
* include/parallel/algorithmfwd.h: Likewise.
* include/parallel/for_each_selectors.h: Likewise.
* include/parallel/balanced_quicksort.h: Likewise.
* include/parallel/merge.h: Likewise.
* include/parallel/algobase.h: Likewise.
* include/parallel/find.h: Likewise.
* include/parallel/algo.h: Likewise.
* include/parallel/checkers.h: Likewise.
2008-01-09 Francesco Biscani <bluescarni@gmail.com> 2008-01-09 Francesco Biscani <bluescarni@gmail.com>
* include/tr1_impl/hashtable (_Hashtable): Fix friend declaration * include/tr1_impl/hashtable (_Hashtable): Fix friend declaration
......
This source diff could not be displayed because it is too large. You can view the blob instead.
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms // software; you can redistribute it and/or modify it under the terms
...@@ -102,7 +102,7 @@ template<typename RandomAccessIterator> ...@@ -102,7 +102,7 @@ template<typename RandomAccessIterator>
* this part. * this part.
* @pre @c (end-begin)>=1 */ * @pre @c (end-begin)>=1 */
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
inline typename std::iterator_traits<RandomAccessIterator>::difference_type typename std::iterator_traits<RandomAccessIterator>::difference_type
qsb_divide(RandomAccessIterator begin, RandomAccessIterator end, qsb_divide(RandomAccessIterator begin, RandomAccessIterator end,
Comparator comp, thread_index_t num_threads) Comparator comp, thread_index_t num_threads)
{ {
...@@ -164,7 +164,7 @@ template<typename RandomAccessIterator, typename Comparator> ...@@ -164,7 +164,7 @@ template<typename RandomAccessIterator, typename Comparator>
* @param num_threads * @param num_threads
* Number of threads that are allowed to work on this part. */ * Number of threads that are allowed to work on this part. */
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
inline void void
qsb_conquer(QSBThreadLocal<RandomAccessIterator>** tls, qsb_conquer(QSBThreadLocal<RandomAccessIterator>** tls,
RandomAccessIterator begin, RandomAccessIterator end, RandomAccessIterator begin, RandomAccessIterator end,
Comparator comp, Comparator comp,
...@@ -240,7 +240,7 @@ template<typename RandomAccessIterator, typename Comparator> ...@@ -240,7 +240,7 @@ template<typename RandomAccessIterator, typename Comparator>
* @param iam Number of the thread processing this function. * @param iam Number of the thread processing this function.
*/ */
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
inline void void
qsb_local_sort_with_helping(QSBThreadLocal<RandomAccessIterator>** tls, qsb_local_sort_with_helping(QSBThreadLocal<RandomAccessIterator>** tls,
Comparator& comp, int iam, bool wait) Comparator& comp, int iam, bool wait)
{ {
...@@ -418,7 +418,7 @@ template<typename RandomAccessIterator, typename Comparator> ...@@ -418,7 +418,7 @@ template<typename RandomAccessIterator, typename Comparator>
* this part. * this part.
*/ */
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
inline void void
parallel_sort_qsb(RandomAccessIterator begin, RandomAccessIterator end, parallel_sort_qsb(RandomAccessIterator begin, RandomAccessIterator end,
Comparator comp, Comparator comp,
typename std::iterator_traits<RandomAccessIterator> typename std::iterator_traits<RandomAccessIterator>
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms // software; you can redistribute it and/or modify it under the terms
...@@ -53,28 +53,32 @@ namespace __gnu_parallel ...@@ -53,28 +53,32 @@ namespace __gnu_parallel
*/ */
// XXX Comparator default template argument // XXX Comparator default template argument
template<typename InputIterator, typename Comparator> template<typename InputIterator, typename Comparator>
bool bool
is_sorted(InputIterator begin, InputIterator end, Comparator comp = std::less<typename std::iterator_traits<InputIterator>::value_type>()) is_sorted(InputIterator begin, InputIterator end,
{ Comparator comp
if (begin == end) = std::less<typename std::iterator_traits<InputIterator>::
return true; value_type>())
{
InputIterator current(begin), recent(begin); if (begin == end)
return true;
InputIterator current(begin), recent(begin);
unsigned long long position = 1;
for (current++; current != end; current++)
{
if (comp(*current, *recent))
{
printf("is_sorted: check failed before position %i.\n",
position);
return false;
}
recent = current;
position++;
}
unsigned long long position = 1; return true;
for (current++; current != end; current++) }
{
if (comp(*current, *recent))
{
printf("is_sorted: check failed before position %i.\n", position);
return false;
}
recent = current;
position++;
}
return true;
}
/** /**
* @brief Check whether @c [begin, @c end) is sorted according to @c comp. * @brief Check whether @c [begin, @c end) is sorted according to @c comp.
...@@ -87,30 +91,35 @@ namespace __gnu_parallel ...@@ -87,30 +91,35 @@ namespace __gnu_parallel
*/ */
// XXX Comparator default template argument // XXX Comparator default template argument
template<typename InputIterator, typename Comparator> template<typename InputIterator, typename Comparator>
bool bool
is_sorted_failure(InputIterator begin, InputIterator end, InputIterator& first_failure, Comparator comp = std::less<typename std::iterator_traits<InputIterator>::value_type>()) is_sorted_failure(InputIterator begin, InputIterator end,
{ InputIterator& first_failure,
if (begin == end) Comparator comp
= std::less<typename std::iterator_traits<InputIterator>::
value_type>())
{
if (begin == end)
return true;
InputIterator current(begin), recent(begin);
unsigned long long position = 1;
for (current++; current != end; current++)
{
if (comp(*current, *recent))
{
first_failure = current;
printf("is_sorted: check failed before position %lld.\n",
position);
return false;
}
recent = current;
position++;
}
first_failure = end;
return true; return true;
}
InputIterator current(begin), recent(begin);
unsigned long long position = 1;
for (current++; current != end; current++)
{
if (comp(*current, *recent))
{
first_failure = current;
printf("is_sorted: check failed before position %lld.\n", position);
return false;
}
recent = current;
position++;
}
first_failure = end;
return true;
}
/** /**
* @brief Check whether @c [begin, @c end) is sorted according to @c comp. * @brief Check whether @c [begin, @c end) is sorted according to @c comp.
...@@ -121,28 +130,31 @@ namespace __gnu_parallel ...@@ -121,28 +130,31 @@ namespace __gnu_parallel
* @return @c true if sorted, @c false otherwise. * @return @c true if sorted, @c false otherwise.
*/ */
template<typename InputIterator, typename Comparator> template<typename InputIterator, typename Comparator>
bool bool
// XXX Comparator default template argument // XXX Comparator default template argument
is_sorted_print_failures(InputIterator begin, InputIterator end, Comparator comp = std::less<typename std::iterator_traits<InputIterator>::value_type>()) is_sorted_print_failures(InputIterator begin, InputIterator end,
{ Comparator comp
if (begin == end) = std::less<typename std::iterator_traits
return true; <InputIterator>::value_type>())
{
InputIterator recent(begin); if (begin == end)
bool ok = true; return true;
for (InputIterator pos(begin + 1); pos != end; pos++) InputIterator recent(begin);
{ bool ok = true;
if (comp(*pos, *recent))
{ for (InputIterator pos(begin + 1); pos != end; pos++)
printf("%ld: %d %d %d %d\n", pos - begin, *(pos - 2), {
*(pos- 1), *pos, *(pos + 1)); if (comp(*pos, *recent))
ok = false; {
} printf("%ld: %d %d %d %d\n", pos - begin, *(pos - 2),
recent = pos; *(pos- 1), *pos, *(pos + 1));
} ok = false;
return ok; }
} recent = pos;
}
return ok;
}
} }
#endif #endif
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms // software; you can redistribute it and/or modify it under the terms
...@@ -58,11 +58,10 @@ namespace __gnu_parallel ...@@ -58,11 +58,10 @@ namespace __gnu_parallel
* @param selector Functionality (e. g. std::find_if (), std::equal(),...) * @param selector Functionality (e. g. std::find_if (), std::equal(),...)
* @return Place of finding in both sequences. * @return Place of finding in both sequences.
*/ */
template< template<typename RandomAccessIterator1,
typename RandomAccessIterator1, typename RandomAccessIterator2,
typename RandomAccessIterator2, typename Pred,
typename Pred, typename Selector>
typename Selector>
std::pair<RandomAccessIterator1, RandomAccessIterator2> std::pair<RandomAccessIterator1, RandomAccessIterator2>
find_template(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, find_template(RandomAccessIterator1 begin1, RandomAccessIterator1 end1,
RandomAccessIterator2 begin2, Pred pred, Selector selector) RandomAccessIterator2 begin2, Pred pred, Selector selector)
...@@ -96,11 +95,10 @@ template< ...@@ -96,11 +95,10 @@ template<
* @param selector Functionality (e. g. std::find_if (), std::equal(),...) * @param selector Functionality (e. g. std::find_if (), std::equal(),...)
* @return Place of finding in both sequences. * @return Place of finding in both sequences.
*/ */
template< template<typename RandomAccessIterator1,
typename RandomAccessIterator1, typename RandomAccessIterator2,
typename RandomAccessIterator2, typename Pred,
typename Pred, typename Selector>
typename Selector>
std::pair<RandomAccessIterator1, RandomAccessIterator2> std::pair<RandomAccessIterator1, RandomAccessIterator2>
find_template(RandomAccessIterator1 begin1, find_template(RandomAccessIterator1 begin1,
RandomAccessIterator1 end1, RandomAccessIterator1 end1,
...@@ -190,11 +188,10 @@ template< ...@@ -190,11 +188,10 @@ template<
* for CSB, the blocks are allocated in a predetermined manner, * for CSB, the blocks are allocated in a predetermined manner,
* namely spacial round-robin. * namely spacial round-robin.
*/ */
template< template<typename RandomAccessIterator1,
typename RandomAccessIterator1, typename RandomAccessIterator2,
typename RandomAccessIterator2, typename Pred,
typename Pred, typename Selector>
typename Selector>
std::pair<RandomAccessIterator1, RandomAccessIterator2> std::pair<RandomAccessIterator1, RandomAccessIterator2>
find_template(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, find_template(RandomAccessIterator1 begin1, RandomAccessIterator1 end1,
RandomAccessIterator2 begin2, Pred pred, Selector selector, RandomAccessIterator2 begin2, Pred pred, Selector selector,
...@@ -311,11 +308,10 @@ template< ...@@ -311,11 +308,10 @@ template<
* blocks are allocated in a predetermined manner, namely spacial * blocks are allocated in a predetermined manner, namely spacial
* round-robin. * round-robin.
*/ */
template< template<typename RandomAccessIterator1,
typename RandomAccessIterator1, typename RandomAccessIterator2,
typename RandomAccessIterator2, typename Pred,
typename Pred, typename Selector>
typename Selector>
std::pair<RandomAccessIterator1, RandomAccessIterator2> std::pair<RandomAccessIterator1, RandomAccessIterator2>
find_template(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, find_template(RandomAccessIterator1 begin1, RandomAccessIterator1 end1,
RandomAccessIterator2 begin2, Pred pred, Selector selector, RandomAccessIterator2 begin2, Pred pred, Selector selector,
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms // software; you can redistribute it and/or modify it under the terms
...@@ -60,10 +60,11 @@ namespace __gnu_parallel ...@@ -60,10 +60,11 @@ namespace __gnu_parallel
* @param i2 Iterator on second sequence (unused). * @param i2 Iterator on second sequence (unused).
* @param pred Find predicate. * @param pred Find predicate.
*/ */
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Pred> template<typename RandomAccessIterator1, typename RandomAccessIterator2,
inline bool typename Pred>
operator()(RandomAccessIterator1 i1, RandomAccessIterator2 i2, Pred pred) bool
{ return pred(*i1); } operator()(RandomAccessIterator1 i1, RandomAccessIterator2 i2, Pred pred)
{ return pred(*i1); }
/** @brief Corresponding sequential algorithm on a sequence. /** @brief Corresponding sequential algorithm on a sequence.
* @param begin1 Begin iterator of first sequence. * @param begin1 Begin iterator of first sequence.
...@@ -71,12 +72,14 @@ namespace __gnu_parallel ...@@ -71,12 +72,14 @@ namespace __gnu_parallel
* @param begin2 Begin iterator of second sequence. * @param begin2 Begin iterator of second sequence.
* @param pred Find predicate. * @param pred Find predicate.
*/ */
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Pred> template<typename RandomAccessIterator1, typename RandomAccessIterator2,
inline std::pair<RandomAccessIterator1, RandomAccessIterator2> typename Pred>
sequential_algorithm(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, Pred pred) std::pair<RandomAccessIterator1, RandomAccessIterator2>
{ sequential_algorithm(RandomAccessIterator1 begin1,
return std::make_pair(find_if(begin1, end1, pred, sequential_tag()), begin2); RandomAccessIterator1 end1,
} RandomAccessIterator2 begin2, Pred pred)
{ return std::make_pair(find_if(begin1, end1, pred,
sequential_tag()), begin2); }
}; };
/** @brief Test predicate on two adjacent elements. */ /** @brief Test predicate on two adjacent elements. */
...@@ -87,13 +90,14 @@ namespace __gnu_parallel ...@@ -87,13 +90,14 @@ namespace __gnu_parallel
* @param i2 Iterator on second sequence (unused). * @param i2 Iterator on second sequence (unused).
* @param pred Find predicate. * @param pred Find predicate.
*/ */
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Pred> template<typename RandomAccessIterator1, typename RandomAccessIterator2,
inline bool typename Pred>
operator()(RandomAccessIterator1 i1, RandomAccessIterator2 i2, Pred pred) bool
{ operator()(RandomAccessIterator1 i1, RandomAccessIterator2 i2, Pred pred)
// Passed end iterator is one short. {
return pred(*i1, *(i1 + 1)); // Passed end iterator is one short.
} return pred(*i1, *(i1 + 1));
}
/** @brief Corresponding sequential algorithm on a sequence. /** @brief Corresponding sequential algorithm on a sequence.
* @param begin1 Begin iterator of first sequence. * @param begin1 Begin iterator of first sequence.
...@@ -101,16 +105,20 @@ namespace __gnu_parallel ...@@ -101,16 +105,20 @@ namespace __gnu_parallel
* @param begin2 Begin iterator of second sequence. * @param begin2 Begin iterator of second sequence.
* @param pred Find predicate. * @param pred Find predicate.
*/ */
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Pred> template<typename RandomAccessIterator1, typename RandomAccessIterator2,
inline std::pair<RandomAccessIterator1, RandomAccessIterator2> typename Pred>
sequential_algorithm(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, Pred pred) std::pair<RandomAccessIterator1, RandomAccessIterator2>
{ sequential_algorithm(RandomAccessIterator1 begin1,
// Passed end iterator is one short. RandomAccessIterator1 end1,
RandomAccessIterator1 spot = adjacent_find(begin1, end1 + 1, pred, sequential_tag()); RandomAccessIterator2 begin2, Pred pred)
if (spot == (end1 + 1)) {
spot = end1; // Passed end iterator is one short.
return std::make_pair(spot, begin2); RandomAccessIterator1 spot = adjacent_find(begin1, end1 + 1,
} pred, sequential_tag());
if (spot == (end1 + 1))
spot = end1;
return std::make_pair(spot, begin2);
}
}; };
/** @brief Test inverted predicate on a single element. */ /** @brief Test inverted predicate on a single element. */
...@@ -122,10 +130,11 @@ namespace __gnu_parallel ...@@ -122,10 +130,11 @@ namespace __gnu_parallel
* @param i2 Iterator on second sequence (unused). * @param i2 Iterator on second sequence (unused).
* @param pred Find predicate. * @param pred Find predicate.
*/ */
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Pred> template<typename RandomAccessIterator1, typename RandomAccessIterator2,
inline bool typename Pred>
operator()(RandomAccessIterator1 i1, RandomAccessIterator2 i2, Pred pred) bool
{ return !pred(*i1, *i2); } operator()(RandomAccessIterator1 i1, RandomAccessIterator2 i2, Pred pred)
{ return !pred(*i1, *i2); }
/** /**
* @brief Corresponding sequential algorithm on a sequence. * @brief Corresponding sequential algorithm on a sequence.
...@@ -134,12 +143,13 @@ namespace __gnu_parallel ...@@ -134,12 +143,13 @@ namespace __gnu_parallel
* @param begin2 Begin iterator of second sequence. * @param begin2 Begin iterator of second sequence.
* @param pred Find predicate. * @param pred Find predicate.
*/ */
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Pred> template<typename RandomAccessIterator1, typename RandomAccessIterator2,
inline std::pair<RandomAccessIterator1, RandomAccessIterator2> typename Pred>
sequential_algorithm(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, Pred pred) std::pair<RandomAccessIterator1, RandomAccessIterator2>
{ sequential_algorithm(RandomAccessIterator1 begin1,
return mismatch(begin1, end1, begin2, pred, sequential_tag()); RandomAccessIterator1 end1,
} RandomAccessIterator2 begin2, Pred pred)
{ return mismatch(begin1, end1, begin2, pred, sequential_tag()); }
}; };
...@@ -157,27 +167,31 @@ namespace __gnu_parallel ...@@ -157,27 +167,31 @@ namespace __gnu_parallel
* @param i1 Iterator on first sequence. * @param i1 Iterator on first sequence.
* @param i2 Iterator on second sequence (unused). * @param i2 Iterator on second sequence (unused).
* @param pred Find predicate. */ * @param pred Find predicate. */
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Pred> template<typename RandomAccessIterator1, typename RandomAccessIterator2,
inline bool typename Pred>
operator()(RandomAccessIterator1 i1, RandomAccessIterator2 i2, Pred pred) bool
{ operator()(RandomAccessIterator1 i1, RandomAccessIterator2 i2, Pred pred)
for (ForwardIterator pos_in_candidates = begin; pos_in_candidates != end; pos_in_candidates++) {
if (pred(*i1, *pos_in_candidates)) for (ForwardIterator pos_in_candidates = begin;
return true; pos_in_candidates != end; ++pos_in_candidates)
return false; if (pred(*i1, *pos_in_candidates))
} return true;
return false;
}
/** @brief Corresponding sequential algorithm on a sequence. /** @brief Corresponding sequential algorithm on a sequence.
* @param begin1 Begin iterator of first sequence. * @param begin1 Begin iterator of first sequence.
* @param end1 End iterator of first sequence. * @param end1 End iterator of first sequence.
* @param begin2 Begin iterator of second sequence. * @param begin2 Begin iterator of second sequence.
* @param pred Find predicate. */ * @param pred Find predicate. */
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Pred> template<typename RandomAccessIterator1, typename RandomAccessIterator2,
inline std::pair<RandomAccessIterator1, RandomAccessIterator2> typename Pred>
sequential_algorithm(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, Pred pred) std::pair<RandomAccessIterator1, RandomAccessIterator2>
{ sequential_algorithm(RandomAccessIterator1 begin1,
return std::make_pair(find_first_of(begin1, end1, begin, end, pred, sequential_tag()), begin2); RandomAccessIterator1 end1,
} RandomAccessIterator2 begin2, Pred pred)
{ return std::make_pair(find_first_of(begin1, end1, begin, end, pred,
sequential_tag()), begin2); }
}; };
} }
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms // software; you can redistribute it and/or modify it under the terms
...@@ -61,22 +61,42 @@ namespace __gnu_parallel ...@@ -61,22 +61,42 @@ namespace __gnu_parallel
* @param output Output iterator. * @param output Output iterator.
* @param bound Maximum number of elements processed. * @param bound Maximum number of elements processed.
* @param parallelism_tag Parallelization method */ * @param parallelism_tag Parallelization method */
template<typename InputIterator, typename UserOp, typename Functionality, typename Red, typename Result> template<typename InputIterator, typename UserOp,
UserOp typename Functionality, typename Red, typename Result>
for_each_template_random_access(InputIterator begin, InputIterator end, UserOp
UserOp user_op, Functionality& functionality, for_each_template_random_access(InputIterator begin, InputIterator end,
Red reduction, Result reduction_start, UserOp user_op,
Result& output, Functionality& functionality,
typename std::iterator_traits<InputIterator>::difference_type bound, parallelism parallelism_tag) Red reduction, Result reduction_start,
{ Result& output, typename
if (parallelism_tag == parallel_unbalanced) std::iterator_traits<InputIterator>::
return for_each_template_random_access_ed(begin, end, user_op, functionality, reduction, reduction_start, output, bound); difference_type bound,
else if (parallelism_tag == parallel_omp_loop) parallelism parallelism_tag)
return for_each_template_random_access_omp_loop(begin, end, user_op, functionality, reduction, reduction_start, output, bound); {
else if (parallelism_tag == parallel_omp_loop_static) if (parallelism_tag == parallel_unbalanced)
return for_each_template_random_access_omp_loop(begin, end, user_op, functionality, reduction, reduction_start, output, bound); return for_each_template_random_access_ed(begin, end, user_op,
else //e. g. parallel_balanced functionality, reduction,
return for_each_template_random_access_workstealing(begin, end, user_op, functionality, reduction, reduction_start, output, bound); reduction_start,
output, bound);
else if (parallelism_tag == parallel_omp_loop)
return for_each_template_random_access_omp_loop(begin, end, user_op,
functionality,
reduction,
reduction_start,
output, bound);
else if (parallelism_tag == parallel_omp_loop_static)
return for_each_template_random_access_omp_loop(begin, end, user_op,
functionality,
reduction,
reduction_start,
output, bound);
else //e. g. parallel_balanced
return for_each_template_random_access_workstealing(begin, end,
user_op,
functionality,
reduction,
reduction_start,
output, bound);
} }
} }
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms // software; you can redistribute it and/or modify it under the terms
...@@ -63,11 +63,12 @@ namespace __gnu_parallel ...@@ -63,11 +63,12 @@ namespace __gnu_parallel
* @param o Operator. * @param o Operator.
* @param i Iterator referencing object. */ * @param i Iterator referencing object. */
template<typename Op> template<typename Op>
inline bool operator()(Op& o, It i) bool
{ operator()(Op& o, It i)
o(*i); {
return true; o(*i);
} return true;
}
}; };
/** @brief std::generate() selector. */ /** @brief std::generate() selector. */
...@@ -78,11 +79,12 @@ namespace __gnu_parallel ...@@ -78,11 +79,12 @@ namespace __gnu_parallel
* @param o Operator. * @param o Operator.
* @param i Iterator referencing object. */ * @param i Iterator referencing object. */
template<typename Op> template<typename Op>
inline bool operator()(Op& o, It i) bool
{ operator()(Op& o, It i)
*i = o(); {
return true; *i = o();
} return true;
}
}; };
/** @brief std::fill() selector. */ /** @brief std::fill() selector. */
...@@ -93,11 +95,12 @@ namespace __gnu_parallel ...@@ -93,11 +95,12 @@ namespace __gnu_parallel
* @param v Current value. * @param v Current value.
* @param i Iterator referencing object. */ * @param i Iterator referencing object. */
template<typename Val> template<typename Val>
inline bool operator()(Val& v, It i) bool
{ operator()(Val& v, It i)
*i = v; {
return true; *i = v;
} return true;
}
}; };
/** @brief std::transform() selector, one input sequence variant. */ /** @brief std::transform() selector, one input sequence variant. */
...@@ -108,11 +111,12 @@ namespace __gnu_parallel ...@@ -108,11 +111,12 @@ namespace __gnu_parallel
* @param o Operator. * @param o Operator.
* @param i Iterator referencing object. */ * @param i Iterator referencing object. */
template<typename Op> template<typename Op>
inline bool operator()(Op& o, It i) bool
{ operator()(Op& o, It i)
*i.second = o(*i.first); {
return true; *i.second = o(*i.first);
} return true;
}
}; };
/** @brief std::transform() selector, two input sequences variant. */ /** @brief std::transform() selector, two input sequences variant. */
...@@ -123,11 +127,12 @@ namespace __gnu_parallel ...@@ -123,11 +127,12 @@ namespace __gnu_parallel
* @param o Operator. * @param o Operator.
* @param i Iterator referencing object. */ * @param i Iterator referencing object. */
template<typename Op> template<typename Op>
inline bool operator()(Op& o, It i) bool
{ operator()(Op& o, It i)
*i.third = o(*i.first, *i.second); {
return true; *i.third = o(*i.first, *i.second);
} return true;
}
}; };
/** @brief std::replace() selector. */ /** @brief std::replace() selector. */
...@@ -144,7 +149,8 @@ namespace __gnu_parallel ...@@ -144,7 +149,8 @@ namespace __gnu_parallel
/** @brief Functor execution. /** @brief Functor execution.
* @param v Current value. * @param v Current value.
* @param i Iterator referencing object. */ * @param i Iterator referencing object. */
inline bool operator()(T& v, It i) bool
operator()(T& v, It i)
{ {
if (*i == v) if (*i == v)
*i = new_val; *i = new_val;
...@@ -166,7 +172,8 @@ namespace __gnu_parallel ...@@ -166,7 +172,8 @@ namespace __gnu_parallel
/** @brief Functor execution. /** @brief Functor execution.
* @param o Operator. * @param o Operator.
* @param i Iterator referencing object. */ * @param i Iterator referencing object. */
inline bool operator()(Op& o, It i) bool
operator()(Op& o, It i)
{ {
if (o(*i)) if (o(*i))
*i = new_val; *i = new_val;
...@@ -183,8 +190,9 @@ namespace __gnu_parallel ...@@ -183,8 +190,9 @@ namespace __gnu_parallel
* @param i Iterator referencing object. * @param i Iterator referencing object.
* @return 1 if count, 0 if does not count. */ * @return 1 if count, 0 if does not count. */
template<typename Val> template<typename Val>
inline Diff operator()(Val& v, It i) Diff
{ return (v == *i) ? 1 : 0; } operator()(Val& v, It i)
{ return (v == *i) ? 1 : 0; }
}; };
/** @brief std::count_if () selector. */ /** @brief std::count_if () selector. */
...@@ -196,8 +204,9 @@ namespace __gnu_parallel ...@@ -196,8 +204,9 @@ namespace __gnu_parallel
* @param i Iterator referencing object. * @param i Iterator referencing object.
* @return 1 if count, 0 if does not count. */ * @return 1 if count, 0 if does not count. */
template<typename Op> template<typename Op>
inline Diff operator()(Op& o, It i) Diff
{ return (o(*i)) ? 1 : 0; } operator()(Op& o, It i)
{ return (o(*i)) ? 1 : 0; }
}; };
/** @brief std::accumulate() selector. */ /** @brief std::accumulate() selector. */
...@@ -209,8 +218,8 @@ namespace __gnu_parallel ...@@ -209,8 +218,8 @@ namespace __gnu_parallel
* @param i Iterator referencing object. * @param i Iterator referencing object.
* @return The current value. */ * @return The current value. */
template<typename Op> template<typename Op>
inline typename std::iterator_traits<It>::value_type operator()(Op o, It i) typename std::iterator_traits<It>::value_type operator()(Op o, It i)
{ return *i; } { return *i; }
}; };
/** @brief std::inner_product() selector. */ /** @brief std::inner_product() selector. */
...@@ -226,18 +235,21 @@ namespace __gnu_parallel ...@@ -226,18 +235,21 @@ namespace __gnu_parallel
/** @brief Constructor. /** @brief Constructor.
* @param b1 Begin iterator of first sequence. * @param b1 Begin iterator of first sequence.
* @param b2 Begin iterator of second sequence. */ * @param b2 Begin iterator of second sequence. */
explicit inner_product_selector(It b1, It2 b2) : begin1_iterator(b1), begin2_iterator(b2) { } explicit inner_product_selector(It b1, It2 b2)
: begin1_iterator(b1), begin2_iterator(b2) { }
/** @brief Functor execution. /** @brief Functor execution.
* @param mult Multiplication functor. * @param mult Multiplication functor.
* @param current Iterator referencing object. * @param current Iterator referencing object.
* @return Inner product elemental result. */ * @return Inner product elemental result. */
template<typename Op> template<typename Op>
inline T operator()(Op mult, It current) T
{ operator()(Op mult, It current)
typename std::iterator_traits<It>::difference_type position = current - begin1_iterator; {
return mult(*current, *(begin2_iterator + position)); typename std::iterator_traits<It>::difference_type position
} = current - begin1_iterator;
return mult(*current, *(begin2_iterator + position));
}
}; };
/** @brief Selector that just returns the passed iterator. */ /** @brief Selector that just returns the passed iterator. */
...@@ -249,8 +261,9 @@ namespace __gnu_parallel ...@@ -249,8 +261,9 @@ namespace __gnu_parallel
* @param i Iterator referencing object. * @param i Iterator referencing object.
* @return Passed iterator. */ * @return Passed iterator. */
template<typename Op> template<typename Op>
inline It operator()(Op o, It i) It
{ return i; } operator()(Op o, It i)
{ return i; }
}; };
/** @brief Selector that returns the difference between two adjacent /** @brief Selector that returns the difference between two adjacent
...@@ -260,13 +273,14 @@ namespace __gnu_parallel ...@@ -260,13 +273,14 @@ namespace __gnu_parallel
struct adjacent_difference_selector : public generic_for_each_selector<It> struct adjacent_difference_selector : public generic_for_each_selector<It>
{ {
template<typename Op> template<typename Op>
inline bool operator()(Op& o, It i) bool
{ operator()(Op& o, It i)
typename It::first_type go_back_one = i.first; {
--go_back_one; typename It::first_type go_back_one = i.first;
*i.second = o(*i.first, *go_back_one); --go_back_one;
return true; *i.second = o(*i.first, *go_back_one);
} return true;
}
}; };
// XXX move into type_traits? // XXX move into type_traits?
...@@ -280,14 +294,15 @@ namespace __gnu_parallel ...@@ -280,14 +294,15 @@ namespace __gnu_parallel
/** @brief Functor execution. /** @brief Functor execution.
* @param i Iterator referencing object. */ * @param i Iterator referencing object. */
template<typename It> template<typename It>
inline void operator()(It i) void
{ } operator()(It i) { }
}; };
/** @brief Reduction function doing nothing. */ /** @brief Reduction function doing nothing. */
struct dummy_reduct struct dummy_reduct
{ {
inline bool operator()(bool /*x*/, bool /*y*/) const bool
operator()(bool /*x*/, bool /*y*/) const
{ return true; } { return true; }
}; };
...@@ -300,7 +315,8 @@ namespace __gnu_parallel ...@@ -300,7 +315,8 @@ namespace __gnu_parallel
explicit min_element_reduct(Comp &c) : comp(c) explicit min_element_reduct(Comp &c) : comp(c)
{ } { }
inline It operator()(It x, It y) It
operator()(It x, It y)
{ {
if (comp(*x, *y)) if (comp(*x, *y))
return x; return x;
...@@ -318,7 +334,8 @@ namespace __gnu_parallel ...@@ -318,7 +334,8 @@ namespace __gnu_parallel
explicit max_element_reduct(Comp& c) : comp(c) explicit max_element_reduct(Comp& c) : comp(c)
{ } { }
inline It operator()(It x, It y) It
operator()(It x, It y)
{ {
if (comp(*x, *y)) if (comp(*x, *y))
return y; return y;
...@@ -336,7 +353,9 @@ namespace __gnu_parallel ...@@ -336,7 +353,9 @@ namespace __gnu_parallel
explicit accumulate_binop_reduct(BinOp& b) : binop(b) {} explicit accumulate_binop_reduct(BinOp& b) : binop(b) {}
template<typename Result, typename Addend> template<typename Result, typename Addend>
Result operator()(const Result& x, const Addend& y) { return binop(x, y); } Result
operator()(const Result& x, const Addend& y)
{ return binop(x, y); }
}; };
} }
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms // software; you can redistribute it and/or modify it under the terms
...@@ -47,156 +47,158 @@ namespace __gnu_parallel ...@@ -47,156 +47,158 @@ namespace __gnu_parallel
* applied to both child iterators. * applied to both child iterators.
*/ */
template<typename Iterator1, typename Iterator2, typename IteratorCategory> template<typename Iterator1, typename Iterator2, typename IteratorCategory>
class iterator_pair : public std::pair<Iterator1, Iterator2> class iterator_pair : public std::pair<Iterator1, Iterator2>
{
private:
typedef iterator_pair<Iterator1, Iterator2, IteratorCategory> type;
typedef std::pair<Iterator1, Iterator2> base_type;
public:
typedef IteratorCategory iterator_category;
typedef void value_type;
typedef std::iterator_traits<Iterator1> traits_type;
typedef typename traits_type::difference_type difference_type;
typedef type* pointer;
typedef type& reference;
iterator_pair() { }
iterator_pair(const Iterator1& first, const Iterator2& second)
: base_type(first, second) { }
// Pre-increment operator.
type&
operator++()
{ {
++base_type::first; private:
++base_type::second; typedef iterator_pair<Iterator1, Iterator2, IteratorCategory> type;
return *this; typedef std::pair<Iterator1, Iterator2> base_type;
}
public:
// Post-increment operator. typedef IteratorCategory iterator_category;
const type typedef void value_type;
operator++(int)
{ return type(base_type::first++, base_type::second++); } typedef std::iterator_traits<Iterator1> traits_type;
typedef typename traits_type::difference_type difference_type;
// Pre-decrement operator. typedef type* pointer;
type& typedef type& reference;
operator--()
{ iterator_pair() { }
--base_type::first;
--base_type::second; iterator_pair(const Iterator1& first, const Iterator2& second)
return *this; : base_type(first, second) { }
}
// Pre-increment operator.
// Post-decrement operator. type&
const type operator++()
operator--(int) {
{ return type(base_type::first--, base_type::second--); } ++base_type::first;
++base_type::second;
// Type conversion. return *this;
operator Iterator2() const }
{ return base_type::second; }
// Post-increment operator.
type& const type
operator=(const type& other) operator++(int)
{ { return type(base_type::first++, base_type::second++); }
base_type::first = other.first;
base_type::second = other.second; // Pre-decrement operator.
return *this; type&
} operator--()
{
type --base_type::first;
operator+(difference_type delta) const --base_type::second;
{ return type(base_type::first + delta, base_type::second + delta); } return *this;
}
difference_type
operator-(const type& other) const // Post-decrement operator.
{ return base_type::first - other.first; } const type
operator--(int)
{ return type(base_type::first--, base_type::second--); }
// Type conversion.
operator Iterator2() const
{ return base_type::second; }
type&
operator=(const type& other)
{
base_type::first = other.first;
base_type::second = other.second;
return *this;
}
type
operator+(difference_type delta) const
{ return type(base_type::first + delta, base_type::second + delta); }
difference_type
operator-(const type& other) const
{ return base_type::first - other.first; }
}; };
/** @brief A triple of iterators. The usual iterator operations are /** @brief A triple of iterators. The usual iterator operations are
applied to all three child iterators. applied to all three child iterators.
*/ */
template<typename Iterator1, typename Iterator2, typename Iterator3, typename IteratorCategory> template<typename Iterator1, typename Iterator2, typename Iterator3,
class iterator_triple typename IteratorCategory>
{ class iterator_triple
private:
typedef iterator_triple<Iterator1, Iterator2, Iterator3, IteratorCategory> type;
public:
typedef IteratorCategory iterator_category;
typedef void value_type;
typedef typename Iterator1::difference_type difference_type;
typedef type* pointer;
typedef type& reference;
Iterator1 first;
Iterator2 second;
Iterator3 third;
iterator_triple() { }
iterator_triple(const Iterator1& _first, const Iterator2& _second,
const Iterator3& _third)
{
first = _first;
second = _second;
third = _third;
}
// Pre-increment operator.
type&
operator++()
{
++first;
++second;
++third;
return *this;
}
// Post-increment operator.
const type
operator++(int)
{ return type(first++, second++, third++); }
// Pre-decrement operator.
type&
operator--()
{
--first;
--second;
--third;
return *this;
}
// Post-decrement operator.
const type
operator--(int)
{ return type(first--, second--, third--); }
// Type conversion.
operator Iterator3() const
{ return third; }
type&
operator=(const type& other)
{ {
first = other.first; private:
second = other.second; typedef iterator_triple<Iterator1, Iterator2, Iterator3,
third = other.third; IteratorCategory> type;
return *this;
} public:
typedef IteratorCategory iterator_category;
type typedef void value_type;
operator+(difference_type delta) const typedef typename Iterator1::difference_type difference_type;
{ return type(first + delta, second + delta, third + delta); } typedef type* pointer;
typedef type& reference;
difference_type
operator-(const type& other) const Iterator1 first;
{ return first - other.first; } Iterator2 second;
Iterator3 third;
iterator_triple() { }
iterator_triple(const Iterator1& _first, const Iterator2& _second,
const Iterator3& _third)
{
first = _first;
second = _second;
third = _third;
}
// Pre-increment operator.
type&
operator++()
{
++first;
++second;
++third;
return *this;
}
// Post-increment operator.
const type
operator++(int)
{ return type(first++, second++, third++); }
// Pre-decrement operator.
type&
operator--()
{
--first;
--second;
--third;
return *this;
}
// Post-decrement operator.
const type
operator--(int)
{ return type(first--, second--, third--); }
// Type conversion.
operator Iterator3() const
{ return third; }
type&
operator=(const type& other)
{
first = other.first;
second = other.second;
third = other.third;
return *this;
}
type
operator+(difference_type delta) const
{ return type(first + delta, second + delta, third + delta); }
difference_type
operator-(const type& other) const
{ return first - other.first; }
}; };
} }
......
// -*- C++ -*- // -*- C++ -*-
// Copyright (C) 2007 Free Software Foundation, Inc. // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms // software; you can redistribute it and/or modify it under the terms
...@@ -52,36 +52,35 @@ namespace __gnu_parallel ...@@ -52,36 +52,35 @@ namespace __gnu_parallel
* grown or not * grown or not
*/ */
template<typename InputIterator> template<typename InputIterator>
void void
shrink_and_double(std::vector<InputIterator>& os_starts, size_t& count_to_two, size_t& range_length, const bool make_twice) shrink_and_double(std::vector<InputIterator>& os_starts,
{ size_t& count_to_two, size_t& range_length,
++count_to_two; const bool make_twice)
if (not make_twice or count_to_two < 2) {
{ ++count_to_two;
if (not make_twice or count_to_two < 2)
shrink(os_starts, count_to_two, range_length); shrink(os_starts, count_to_two, range_length);
} else
else {
{ os_starts.resize((os_starts.size() - 1) * 2 + 1);
os_starts.resize((os_starts.size() - 1) * 2 + 1); count_to_two = 0;
count_to_two = 0; }
} }
}
/** @brief Combines two ranges into one and thus halves the number of ranges. /** @brief Combines two ranges into one and thus halves the number of ranges.
* @param os_starts Start positions worked on (oversampled). * @param os_starts Start positions worked on (oversampled).
* @param count_to_two Counts up to 2. * @param count_to_two Counts up to 2.
* @param range_length Current length of a chunk. */ * @param range_length Current length of a chunk. */
template<typename InputIterator> template<typename InputIterator>
void void
shrink(std::vector<InputIterator>& os_starts, size_t& count_to_two, shrink(std::vector<InputIterator>& os_starts, size_t& count_to_two,
size_t& range_length) size_t& range_length)
{ {
for (typename std::vector<InputIterator>::size_type i = 0; i <= (os_starts.size() / 2); ++i) for (typename std::vector<InputIterator>::size_type i = 0;
{ i <= (os_starts.size() / 2); ++i)
os_starts[i] = os_starts[i * 2]; os_starts[i] = os_starts[i * 2];
} range_length *= 2;
range_length *= 2; }
}
/** @brief Splits a sequence given by input iterators into parts of /** @brief Splits a sequence given by input iterators into parts of
* almost equal size * almost equal size
...@@ -103,79 +102,81 @@ namespace __gnu_parallel ...@@ -103,79 +102,81 @@ namespace __gnu_parallel
* @return Length of the whole sequence. * @return Length of the whole sequence.
*/ */
template<typename InputIterator, typename FunctorType> template<typename InputIterator, typename FunctorType>
size_t size_t
list_partition(const InputIterator begin, const InputIterator end, list_partition(const InputIterator begin, const InputIterator end,
InputIterator* starts, size_t* lengths, const int num_parts, InputIterator* starts, size_t* lengths, const int num_parts,
FunctorType& f, int oversampling = 0) FunctorType& f, int oversampling = 0)
{ {
bool make_twice = false; bool make_twice = false;
// According to the oversampling factor, the resizing algorithm is chosen. // According to the oversampling factor, the resizing algorithm is chosen.
if (oversampling == 0) if (oversampling == 0)
{ {
make_twice = true; make_twice = true;
oversampling = 1; oversampling = 1;
} }
std::vector<InputIterator> os_starts(2 * oversampling * num_parts + 1); std::vector<InputIterator> os_starts(2 * oversampling * num_parts + 1);
os_starts[0]= begin; os_starts[0]= begin;
InputIterator prev = begin, it = begin; InputIterator prev = begin, it = begin;
size_t dist_limit = 0, dist = 0; size_t dist_limit = 0, dist = 0;
size_t cur = 1, next = 1; size_t cur = 1, next = 1;
size_t range_length = 1; size_t range_length = 1;
size_t count_to_two = 0; size_t count_to_two = 0;
while (it != end){ while (it != end)
cur = next;
for (; cur < os_starts.size() and it != end; ++cur)
{ {
for (dist_limit += range_length; dist < dist_limit and it != end; ++dist) cur = next;
for (; cur < os_starts.size() and it != end; ++cur)
{ {
f(it); for (dist_limit += range_length;
++it; dist < dist_limit and it != end; ++dist)
{
f(it);
++it;
}
os_starts[cur] = it;
} }
os_starts[cur] = it;
// Must compare for end and not cur < os_starts.size() , because
// cur could be == os_starts.size() as well
if (it == end)
break;
shrink_and_double(os_starts, count_to_two, range_length, make_twice);
next = os_starts.size() / 2 + 1;
} }
// Must compare for end and not cur < os_starts.size() , because // Calculation of the parts (one must be extracted from current
// cur could be == os_starts.size() as well // because the partition beginning at end, consists only of
if (it == end) // itself).
break; size_t size_part = (cur - 1) / num_parts;
int size_greater = static_cast<int>((cur - 1) % num_parts);
starts[0] = os_starts[0];
shrink_and_double(os_starts, count_to_two, range_length, make_twice); size_t index = 0;
next = os_starts.size()/2 + 1;
}
// Calculation of the parts (one must be extracted from current // Smallest partitions.
// because the partition beginning at end, consists only of for (int i = 1; i < (num_parts + 1 - size_greater); ++i)
// itself). {
size_t size_part = (cur - 1) / num_parts; lengths[i-1] = size_part * range_length;
int size_greater = static_cast<int>((cur - 1) % num_parts); index += size_part;
starts[0] = os_starts[0]; starts[i] = os_starts[index];
}
size_t index = 0;
// Biggest partitions.
// Smallest partitions. for (int i = num_parts + 1 - size_greater; i <= num_parts; ++i)
for (int i = 1; i < (num_parts + 1 - size_greater); ++i) {
{ lengths[i-1] = (size_part+1) * range_length;
lengths[i-1] = size_part * range_length; index += (size_part+1);
index += size_part; starts[i] = os_starts[index];
starts[i] = os_starts[index]; }
}
// Correction of the end size (the end iteration has not finished).
// Biggest partitions. lengths[num_parts - 1] -= (dist_limit - dist);
for (int i = num_parts + 1 - size_greater; i <= num_parts; ++i)
{ return dist;
lengths[i-1] = (size_part+1) * range_length; }
index += (size_part+1);
starts[i] = os_starts[index];
}
// Correction of the end size (the end iteration has not finished).
lengths[num_parts - 1] -= (dist_limit - dist);
return dist;
}
} }
#endif #endif
...@@ -76,9 +76,8 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -76,9 +76,8 @@ template<typename T, typename Comparator = std::less<T> >
Comparator comp; Comparator comp;
public: public:
inline
LoserTreeExplicit(unsigned int _size, Comparator _comp = std::less<T>()) LoserTreeExplicit(unsigned int _size, Comparator _comp = std::less<T>())
: comp(_comp) : comp(_comp)
{ {
size = _size; size = _size;
offset = size; offset = size;
...@@ -92,14 +91,14 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -92,14 +91,14 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline ~LoserTreeExplicit() ~LoserTreeExplicit()
{ delete[] losers; } { delete[] losers; }
inline int int
get_min_source() get_min_source()
{ return losers[0].source; } { return losers[0].source; }
inline void void
insert_start(T key, int source, bool sup) insert_start(T key, int source, bool sup)
{ {
bool inf = false; bool inf = false;
...@@ -122,10 +121,10 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -122,10 +121,10 @@ template<typename T, typename Comparator = std::less<T> >
losers[0].source = source; losers[0].source = source;
} }
inline void void
init() { } init() { }
inline void void
delete_min_insert(T key, bool sup) delete_min_insert(T key, bool sup)
{ {
bool inf = false; bool inf = false;
...@@ -151,7 +150,7 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -151,7 +150,7 @@ template<typename T, typename Comparator = std::less<T> >
losers[0].source = source; losers[0].source = source;
} }
inline void void
insert_start_stable(T key, int source, bool sup) insert_start_stable(T key, int source, bool sup)
{ {
bool inf = false; bool inf = false;
...@@ -176,10 +175,10 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -176,10 +175,10 @@ template<typename T, typename Comparator = std::less<T> >
losers[0].source = source; losers[0].source = source;
} }
inline void void
init_stable() { } init_stable() { }
inline void void
delete_min_insert_stable(T key, bool sup) delete_min_insert_stable(T key, bool sup)
{ {
bool inf = false; bool inf = false;
...@@ -233,7 +232,7 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -233,7 +232,7 @@ template<typename T, typename Comparator = std::less<T> >
bool first_insert; bool first_insert;
public: public:
inline LoserTree(unsigned int _k, Comparator _comp = std::less<T>()) LoserTree(unsigned int _k, Comparator _comp = std::less<T>())
: comp(_comp) : comp(_comp)
{ {
ik = _k; ik = _k;
...@@ -249,14 +248,14 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -249,14 +248,14 @@ template<typename T, typename Comparator = std::less<T> >
first_insert = true; first_insert = true;
} }
inline ~LoserTree() ~LoserTree()
{ ::operator delete(losers); } { ::operator delete(losers); }
inline int int
get_min_source() get_min_source()
{ return losers[0].source; } { return losers[0].source; }
inline void void
insert_start(const T& key, int source, bool sup) insert_start(const T& key, int source, bool sup)
{ {
unsigned int pos = k + source; unsigned int pos = k + source;
...@@ -303,12 +302,12 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -303,12 +302,12 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
init() init()
{ losers[0] = losers[init_winner(1)]; } { losers[0] = losers[init_winner(1)]; }
// Do not pass const reference since key will be used as local variable. // Do not pass const reference since key will be used as local variable.
inline void void
delete_min_insert(T key, bool sup) delete_min_insert(T key, bool sup)
{ {
int source = losers[0].source; int source = losers[0].source;
...@@ -329,7 +328,7 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -329,7 +328,7 @@ template<typename T, typename Comparator = std::less<T> >
losers[0].key = key; losers[0].key = key;
} }
inline void void
insert_start_stable(const T& key, int source, bool sup) insert_start_stable(const T& key, int source, bool sup)
{ return insert_start(key, source, sup); } { return insert_start(key, source, sup); }
...@@ -361,12 +360,12 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -361,12 +360,12 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
init_stable() init_stable()
{ losers[0] = losers[init_winner_stable(1)]; } { losers[0] = losers[init_winner_stable(1)]; }
// Do not pass const reference since key will be used as local variable. // Do not pass const reference since key will be used as local variable.
inline void void
delete_min_insert_stable(T key, bool sup) delete_min_insert_stable(T key, bool sup)
{ {
int source = losers[0].source; int source = losers[0].source;
...@@ -432,9 +431,8 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -432,9 +431,8 @@ template<typename T, typename Comparator = std::less<T> >
Comparator comp; Comparator comp;
public: public:
inline
LoserTreeReference(unsigned int _k, Comparator _comp = std::less<T>()) LoserTreeReference(unsigned int _k, Comparator _comp = std::less<T>())
: comp(_comp) : comp(_comp)
{ {
ik = _k; ik = _k;
...@@ -449,7 +447,7 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -449,7 +447,7 @@ template<typename T, typename Comparator = std::less<T> >
losers[i + k].sup = true; losers[i + k].sup = true;
} }
inline ~LoserTreeReference() ~LoserTreeReference()
{ {
delete[] losers; delete[] losers;
#ifndef COPY #ifndef COPY
...@@ -457,11 +455,11 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -457,11 +455,11 @@ template<typename T, typename Comparator = std::less<T> >
#endif #endif
} }
inline int int
get_min_source() get_min_source()
{ return losers[0].source; } { return losers[0].source; }
inline void void
insert_start(T key, int source, bool sup) insert_start(T key, int source, bool sup)
{ {
unsigned int pos = k + source; unsigned int pos = k + source;
...@@ -498,13 +496,13 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -498,13 +496,13 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
init() init()
{ {
losers[0] = losers[init_winner(1)]; losers[0] = losers[init_winner(1)];
} }
inline void void
delete_min_insert(T key, bool sup) delete_min_insert(T key, bool sup)
{ {
int source = losers[0].source; int source = losers[0].source;
...@@ -529,7 +527,7 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -529,7 +527,7 @@ template<typename T, typename Comparator = std::less<T> >
#endif #endif
} }
inline void void
insert_start_stable(T key, int source, bool sup) insert_start_stable(T key, int source, bool sup)
{ return insert_start(key, source, sup); } { return insert_start(key, source, sup); }
...@@ -560,11 +558,11 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -560,11 +558,11 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
init_stable() init_stable()
{ losers[0] = losers[init_winner_stable(1)]; } { losers[0] = losers[init_winner_stable(1)]; }
inline void void
delete_min_insert_stable(T key, bool sup) delete_min_insert_stable(T key, bool sup)
{ {
int source = losers[0].source; int source = losers[0].source;
...@@ -622,7 +620,6 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -622,7 +620,6 @@ template<typename T, typename Comparator = std::less<T> >
Comparator comp; Comparator comp;
public: public:
inline
LoserTreePointer(unsigned int _k, Comparator _comp = std::less<T>()) LoserTreePointer(unsigned int _k, Comparator _comp = std::less<T>())
: comp(_comp) : comp(_comp)
{ {
...@@ -636,14 +633,14 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -636,14 +633,14 @@ template<typename T, typename Comparator = std::less<T> >
losers[i + k].sup = true; losers[i + k].sup = true;
} }
inline ~LoserTreePointer() ~LoserTreePointer()
{ delete[] losers; } { delete[] losers; }
inline int int
get_min_source() get_min_source()
{ return losers[0].source; } { return losers[0].source; }
inline void void
insert_start(const T& key, int source, bool sup) insert_start(const T& key, int source, bool sup)
{ {
unsigned int pos = k + source; unsigned int pos = k + source;
...@@ -657,9 +654,7 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -657,9 +654,7 @@ template<typename T, typename Comparator = std::less<T> >
init_winner(unsigned int root) init_winner(unsigned int root)
{ {
if (root >= k) if (root >= k)
{ return root;
return root;
}
else else
{ {
unsigned int left = init_winner (2 * root); unsigned int left = init_winner (2 * root);
...@@ -681,11 +676,11 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -681,11 +676,11 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
init() init()
{ losers[0] = losers[init_winner(1)]; } { losers[0] = losers[init_winner(1)]; }
inline void void
delete_min_insert(const T& key, bool sup) delete_min_insert(const T& key, bool sup)
{ {
const T* keyp = &key; const T* keyp = &key;
...@@ -707,7 +702,7 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -707,7 +702,7 @@ template<typename T, typename Comparator = std::less<T> >
losers[0].keyp = keyp; losers[0].keyp = keyp;
} }
inline void void
insert_start_stable(const T& key, int source, bool sup) insert_start_stable(const T& key, int source, bool sup)
{ return insert_start(key, source, sup); } { return insert_start(key, source, sup); }
...@@ -739,11 +734,11 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -739,11 +734,11 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
init_stable() init_stable()
{ losers[0] = losers[init_winner_stable(1)]; } { losers[0] = losers[init_winner_stable(1)]; }
inline void void
delete_min_insert_stable(const T& key, bool sup) delete_min_insert_stable(const T& key, bool sup)
{ {
const T* keyp = &key; const T* keyp = &key;
...@@ -810,9 +805,8 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -810,9 +805,8 @@ template<typename T, typename Comparator = std::less<T> >
} }
public: public:
inline
LoserTreeUnguarded(unsigned int _k, Comparator _comp = std::less<T>()) LoserTreeUnguarded(unsigned int _k, Comparator _comp = std::less<T>())
: comp(_comp) : comp(_comp)
{ {
ik = _k; ik = _k;
// Next greater or equal power of 2. // Next greater or equal power of 2.
...@@ -823,17 +817,17 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -823,17 +817,17 @@ template<typename T, typename Comparator = std::less<T> >
map(1, 0, ik); map(1, 0, ik);
} }
inline ~LoserTreeUnguarded() ~LoserTreeUnguarded()
{ {
delete[] losers; delete[] losers;
delete[] mapping; delete[] mapping;
} }
inline int int
get_min_source() get_min_source()
{ return losers[0].source; } { return losers[0].source; }
inline void void
insert_start(const T& key, int source, bool) insert_start(const T& key, int source, bool)
{ {
unsigned int pos = mapping[source]; unsigned int pos = mapping[source];
...@@ -868,12 +862,12 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -868,12 +862,12 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
init() init()
{ losers[0] = losers[init_winner(1, 0, ik)]; } { losers[0] = losers[init_winner(1, 0, ik)]; }
// Do not pass const reference since key will be used as local variable. // Do not pass const reference since key will be used as local variable.
inline void void
delete_min_insert(const T& key, bool) delete_min_insert(const T& key, bool)
{ {
losers[0].key = key; losers[0].key = key;
...@@ -891,15 +885,15 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -891,15 +885,15 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
insert_start_stable(const T& key, int source, bool) insert_start_stable(const T& key, int source, bool)
{ return insert_start(key, source, false); } { return insert_start(key, source, false); }
inline void void
init_stable() init_stable()
{ init(); } { init(); }
inline void void
delete_min_insert_stable(const T& key, bool) delete_min_insert_stable(const T& key, bool)
{ {
losers[0].key = key; losers[0].key = key;
...@@ -959,10 +953,9 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -959,10 +953,9 @@ template<typename T, typename Comparator = std::less<T> >
} }
public: public:
inline
LoserTreePointerUnguarded(unsigned int _k, LoserTreePointerUnguarded(unsigned int _k,
Comparator _comp = std::less<T>()) Comparator _comp = std::less<T>())
: comp(_comp) : comp(_comp)
{ {
ik = _k; ik = _k;
...@@ -974,17 +967,17 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -974,17 +967,17 @@ template<typename T, typename Comparator = std::less<T> >
map(1, 0, ik); map(1, 0, ik);
} }
inline ~LoserTreePointerUnguarded() ~LoserTreePointerUnguarded()
{ {
delete[] losers; delete[] losers;
delete[] mapping; delete[] mapping;
} }
inline int int
get_min_source() get_min_source()
{ return losers[0].source; } { return losers[0].source; }
inline void void
insert_start(const T& key, int source, bool) insert_start(const T& key, int source, bool)
{ {
unsigned int pos = mapping[source]; unsigned int pos = mapping[source];
...@@ -1019,13 +1012,11 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -1019,13 +1012,11 @@ template<typename T, typename Comparator = std::less<T> >
} }
} }
inline void void
init() init()
{ { losers[0] = losers[init_winner(1, 0, ik)]; }
losers[0] = losers[init_winner(1, 0, ik)];
}
inline void void
delete_min_insert(const T& key, bool) delete_min_insert(const T& key, bool)
{ {
const T* keyp = &key; const T* keyp = &key;
...@@ -1044,15 +1035,15 @@ template<typename T, typename Comparator = std::less<T> > ...@@ -1044,15 +1035,15 @@ template<typename T, typename Comparator = std::less<T> >
losers[0].keyp = keyp; losers[0].keyp = keyp;
} }
inline void void
insert_start_stable(const T& key, int source, bool) insert_start_stable(const T& key, int source, bool)
{ return insert_start(key, source, false); } { return insert_start(key, source, false); }
inline void void
init_stable() init_stable()
{ init(); } { init(); }
inline void void
delete_min_insert_stable(const T& key, bool) delete_min_insert_stable(const T& key, bool)
{ {
int& source = losers[0].source; int& source = losers[0].source;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment