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