This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[v3] Fix some minor uglification and formatting issues in parallel
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 04 Nov 2009 19:49:53 +0100
- Subject: [v3] Fix some minor uglification and formatting issues in parallel
Hi,
tested x86_64-linux, committed to mainline.
Paolo.
//////////////////
2009-11-04 Paolo Carlini <paolo.carlini@oracle.com>
* include/parallel/multiway_merge.h: Simple formatting and
uglification fixes.
* include/parallel/losertree.h: Likewise.
Index: include/parallel/multiway_merge.h
===================================================================
--- include/parallel/multiway_merge.h (revision 153902)
+++ include/parallel/multiway_merge.h (working copy)
@@ -510,9 +510,9 @@
/** @brief Multi-way merging procedure for a high branching factor,
* guarded case.
*
- * This merging variant uses a LoserTree class as selected by <tt>LT</tt>.
+ * This merging variant uses a LoserTree class as selected by <tt>_LT</tt>.
*
- * Stability is selected through the used LoserTree class <tt>LT</tt>.
+ * Stability is selected through the used LoserTree class <tt>_LT</tt>.
*
* At least one non-empty sequence is required.
*
@@ -525,7 +525,7 @@
*
* @return End iterator of output sequence.
*/
-template<typename LT,
+template<typename _LT,
typename _RAIterIterator,
typename _RAIter3,
typename _DifferenceTp,
@@ -547,7 +547,7 @@
int __k = static_cast<int>(__seqs_end - __seqs_begin);
- LT __lt(__k, __comp);
+ _LT __lt(__k, __comp);
// Default value for potentially non-default-constructible types.
_ValueType* __arbitrary_element = NULL;
@@ -592,7 +592,7 @@
/** @brief Multi-way merging procedure for a high branching factor,
* unguarded case.
*
- * Merging is done using the LoserTree class <tt>LT</tt>.
+ * Merging is done using the LoserTree class <tt>_LT</tt>.
*
* Stability is selected by the used LoserTrees.
*
@@ -607,10 +607,10 @@
*
* @return End iterator of output sequence.
*/
-template<typename LT,
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp, typename _Compare>
+template<typename _LT,
+ typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp, typename _Compare>
_RAIter3
multiway_merge_loser_tree_unguarded(
_RAIterIterator __seqs_begin,
@@ -633,7 +633,7 @@
int __k = __seqs_end - __seqs_begin;
- LT __lt(__k, __sentinel, __comp);
+ _LT __lt(__k, __sentinel, __comp);
for (int __t = 0; __t < __k; ++__t)
{
@@ -696,12 +696,11 @@
*
* @return End iterator of output sequence.
*/
-template<
- typename UnguardedLoserTree,
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Compare>
+template<typename UnguardedLoserTree,
+ typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Compare>
_RAIter3
multiway_merge_loser_tree_sentinel(
_RAIterIterator __seqs_begin,
@@ -790,172 +789,159 @@
*
* Note that 3-way merging is always stable!
*/
-template<
- bool __sentinels /*default == false*/,
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Compare>
-struct __multiway_merge_3_variant_sentinel_switch
-{
- _RAIter3 operator()(
- _RAIterIterator __seqs_begin,
- _RAIterIterator __seqs_end,
- _RAIter3 __target,
- _DifferenceTp __length, _Compare __comp)
+template<bool __sentinels /*default == false*/,
+ typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Compare>
+ struct __multiway_merge_3_variant_sentinel_switch
{
- return multiway_merge_3_variant<_GuardedIterator>(
- __seqs_begin, __seqs_end, __target, __length, __comp);
- }
-};
+ _RAIter3 operator()(_RAIterIterator __seqs_begin,
+ _RAIterIterator __seqs_end,
+ _RAIter3 __target,
+ _DifferenceTp __length, _Compare __comp)
+ {
+ return multiway_merge_3_variant<_GuardedIterator>
+ (__seqs_begin, __seqs_end, __target, __length, __comp);
+ }
+ };
/**
* @brief Switch for 3-way merging with __sentinels turned on.
*
* Note that 3-way merging is always stable!
*/
-template<
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Compare>
-struct __multiway_merge_3_variant_sentinel_switch
- <true, _RAIterIterator, _RAIter3,
- _DifferenceTp, _Compare>
-{
- _RAIter3 operator()(
- _RAIterIterator __seqs_begin,
- _RAIterIterator __seqs_end,
- _RAIter3 __target,
- _DifferenceTp __length, _Compare __comp)
+template<typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Compare>
+ struct __multiway_merge_3_variant_sentinel_switch
+ <true, _RAIterIterator, _RAIter3, _DifferenceTp, _Compare>
{
- return multiway_merge_3_variant<_UnguardedIterator>(
- __seqs_begin, __seqs_end, __target, __length, __comp);
- }
-};
+ _RAIter3 operator()(_RAIterIterator __seqs_begin,
+ _RAIterIterator __seqs_end,
+ _RAIter3 __target,
+ _DifferenceTp __length, _Compare __comp)
+ {
+ return multiway_merge_3_variant<_UnguardedIterator>
+ (__seqs_begin, __seqs_end, __target, __length, __comp);
+ }
+ };
/**
* @brief Switch for 4-way merging with __sentinels turned off.
*
* Note that 4-way merging is always stable!
*/
-template<
- bool __sentinels /*default == false*/,
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Compare>
-struct __multiway_merge_4_variant_sentinel_switch
-{
- _RAIter3 operator()(
- _RAIterIterator __seqs_begin,
- _RAIterIterator __seqs_end,
- _RAIter3 __target,
- _DifferenceTp __length, _Compare __comp)
+template<bool __sentinels /*default == false*/,
+ typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Compare>
+ struct __multiway_merge_4_variant_sentinel_switch
{
- return multiway_merge_4_variant<_GuardedIterator>(
- __seqs_begin, __seqs_end, __target, __length, __comp);
- }
-};
+ _RAIter3 operator()(_RAIterIterator __seqs_begin,
+ _RAIterIterator __seqs_end,
+ _RAIter3 __target,
+ _DifferenceTp __length, _Compare __comp)
+ {
+ return multiway_merge_4_variant<_GuardedIterator>
+ (__seqs_begin, __seqs_end, __target, __length, __comp);
+ }
+ };
/**
* @brief Switch for 4-way merging with __sentinels turned on.
*
* Note that 4-way merging is always stable!
*/
-template<
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Compare>
-struct __multiway_merge_4_variant_sentinel_switch
- <true, _RAIterIterator, _RAIter3,
- _DifferenceTp, _Compare>
-{
- _RAIter3 operator()(
- _RAIterIterator __seqs_begin,
- _RAIterIterator __seqs_end,
- _RAIter3 __target,
- _DifferenceTp __length, _Compare __comp)
+template<typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Compare>
+ struct __multiway_merge_4_variant_sentinel_switch
+ <true, _RAIterIterator, _RAIter3, _DifferenceTp, _Compare>
{
- return multiway_merge_4_variant<_UnguardedIterator>(
- __seqs_begin, __seqs_end, __target, __length, __comp);
- }
-};
+ _RAIter3 operator()(_RAIterIterator __seqs_begin,
+ _RAIterIterator __seqs_end,
+ _RAIter3 __target,
+ _DifferenceTp __length, _Compare __comp)
+ {
+ return multiway_merge_4_variant<_UnguardedIterator>
+ (__seqs_begin, __seqs_end, __target, __length, __comp);
+ }
+ };
/**
* @brief Switch for k-way merging with __sentinels turned on.
*/
-template<
- bool __sentinels,
- bool __stable,
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Compare>
-struct __multiway_merge_k_variant_sentinel_switch
-{
- _RAIter3 operator()(
- _RAIterIterator __seqs_begin,
+template<bool __sentinels,
+ bool __stable,
+ typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Compare>
+ struct __multiway_merge_k_variant_sentinel_switch
+ {
+ _RAIter3 operator()
+ (_RAIterIterator __seqs_begin,
_RAIterIterator __seqs_end,
_RAIter3 __target,
const typename std::iterator_traits<typename std::iterator_traits<
- _RAIterIterator>::value_type::first_type>::value_type&
- __sentinel,
+ _RAIterIterator>::value_type::first_type>::value_type&
+ __sentinel,
_DifferenceTp __length, _Compare __comp)
- {
- typedef typename std::iterator_traits<_RAIterIterator>
- ::value_type::first_type
- _RAIter1;
- typedef typename std::iterator_traits<_RAIter1>::value_type
- _ValueType;
+ {
+ typedef typename std::iterator_traits<_RAIterIterator>
+ ::value_type::first_type
+ _RAIter1;
+ typedef typename std::iterator_traits<_RAIter1>::value_type
+ _ValueType;
- return multiway_merge_loser_tree_sentinel<
- typename __gnu_cxx::__conditional_type<
- _LoserTreeTraits<_ValueType>::_M_use_pointer
- , _LoserTreePointerUnguarded<__stable, _ValueType, _Compare>
- , _LoserTreeUnguarded<__stable, _ValueType, _Compare>
+ return multiway_merge_loser_tree_sentinel<
+ typename __gnu_cxx::__conditional_type<
+ _LoserTreeTraits<_ValueType>::_M_use_pointer,
+ _LoserTreePointerUnguarded<__stable, _ValueType, _Compare>,
+ _LoserTreeUnguarded<__stable, _ValueType, _Compare>
>::__type>(
__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp);
- }
-};
+ }
+ };
/**
* @brief Switch for k-way merging with __sentinels turned off.
*/
-template<
- bool __stable,
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Compare>
-struct __multiway_merge_k_variant_sentinel_switch
- <false, __stable, _RAIterIterator, _RAIter3,
- _DifferenceTp, _Compare>
-{
- _RAIter3 operator()(
- _RAIterIterator __seqs_begin,
- _RAIterIterator __seqs_end,
- _RAIter3 __target,
- const typename std::iterator_traits<typename std::iterator_traits<
- _RAIterIterator>::value_type::first_type>::value_type&
- __sentinel,
- _DifferenceTp __length, _Compare __comp)
+template<bool __stable,
+ typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Compare>
+ struct __multiway_merge_k_variant_sentinel_switch
+ <false, __stable, _RAIterIterator, _RAIter3, _DifferenceTp, _Compare>
{
- typedef typename std::iterator_traits<_RAIterIterator>
- ::value_type::first_type
- _RAIter1;
- typedef typename std::iterator_traits<_RAIter1>::value_type
- _ValueType;
+ _RAIter3 operator()
+ (_RAIterIterator __seqs_begin,
+ _RAIterIterator __seqs_end,
+ _RAIter3 __target,
+ const typename std::iterator_traits<typename std::iterator_traits<
+ _RAIterIterator>::value_type::first_type>::value_type&
+ __sentinel,
+ _DifferenceTp __length, _Compare __comp)
+ {
+ typedef typename std::iterator_traits<_RAIterIterator>
+ ::value_type::first_type
+ _RAIter1;
+ typedef typename std::iterator_traits<_RAIter1>::value_type
+ _ValueType;
- return multiway_merge_loser_tree<
- typename __gnu_cxx::__conditional_type<
- _LoserTreeTraits<_ValueType>::_M_use_pointer
- , _LoserTreePointer<__stable, _ValueType, _Compare>
- , _LoserTree<__stable, _ValueType, _Compare>
+ return multiway_merge_loser_tree<
+ typename __gnu_cxx::__conditional_type<
+ _LoserTreeTraits<_ValueType>::_M_use_pointer,
+ _LoserTreePointer<__stable, _ValueType, _Compare>,
+ _LoserTree<__stable, _ValueType, _Compare>
>::__type >(__seqs_begin, __seqs_end, __target, __length, __comp);
- }
-};
+ }
+ };
/** @brief Sequential multi-way merging switch.
*
@@ -970,13 +956,12 @@
* @param __stable Stable merging incurs a performance penalty.
* @param __sentinel The sequences have __a __sentinel element.
* @return End iterator of output sequence. */
-template<
- bool __stable,
- bool __sentinels,
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Compare>
+template<bool __stable,
+ bool __sentinels,
+ typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Compare>
_RAIter3
__sequential_multiway_merge(
_RAIterIterator __seqs_begin,
@@ -1035,30 +1020,30 @@
break;
case 3:
__return_target = __multiway_merge_3_variant_sentinel_switch<
- __sentinels
- , _RAIterIterator
- , _RAIter3
- , _DifferenceTp
- , _Compare>()(__seqs_begin, __seqs_end, __target, __length, __comp);
+ __sentinels,
+ _RAIterIterator,
+ _RAIter3,
+ _DifferenceTp,
+ _Compare>()(__seqs_begin, __seqs_end, __target, __length, __comp);
break;
case 4:
__return_target = __multiway_merge_4_variant_sentinel_switch<
- __sentinels
- , _RAIterIterator
- , _RAIter3
- , _DifferenceTp
- , _Compare>()(__seqs_begin, __seqs_end, __target, __length, __comp);
+ __sentinels,
+ _RAIterIterator,
+ _RAIter3,
+ _DifferenceTp,
+ _Compare>()(__seqs_begin, __seqs_end, __target, __length, __comp);
break;
default:
- __return_target = __multiway_merge_k_variant_sentinel_switch<
- __sentinels
- , __stable
- , _RAIterIterator
- , _RAIter3
- , _DifferenceTp
- , _Compare>()(__seqs_begin, __seqs_end, __target, __sentinel,
- __length, __comp);
- break;
+ __return_target = __multiway_merge_k_variant_sentinel_switch<
+ __sentinels,
+ __stable,
+ _RAIterIterator,
+ _RAIter3,
+ _DifferenceTp,
+ _Compare>()(__seqs_begin, __seqs_end, __target, __sentinel,
+ __length, __comp);
+ break;
}
#if _GLIBCXX_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(
@@ -1074,12 +1059,12 @@
* Used to reduce code instanciation in multiway_merge_sampling_splitting.
*/
template<bool __stable, class _RAIter, class _StrictWeakOrdering>
-struct _SamplingSorter
-{
- void operator()(_RAIter __first, _RAIter __last,
- _StrictWeakOrdering __comp)
- { __gnu_sequential::stable_sort(__first, __last, __comp); }
-};
+ struct _SamplingSorter
+ {
+ void operator()(_RAIter __first, _RAIter __last,
+ _StrictWeakOrdering __comp)
+ { __gnu_sequential::stable_sort(__first, __last, __comp); }
+ };
/**
* @brief Non-__stable sorting functor.
@@ -1087,178 +1072,176 @@
* Used to reduce code instantiation in multiway_merge_sampling_splitting.
*/
template<class _RAIter, class _StrictWeakOrdering>
-struct _SamplingSorter<false, _RAIter, _StrictWeakOrdering>
-{
- void operator()(_RAIter __first, _RAIter __last,
- _StrictWeakOrdering __comp)
- { __gnu_sequential::sort(__first, __last, __comp); }
-};
+ struct _SamplingSorter<false, _RAIter, _StrictWeakOrdering>
+ {
+ void operator()(_RAIter __first, _RAIter __last,
+ _StrictWeakOrdering __comp)
+ { __gnu_sequential::sort(__first, __last, __comp); }
+ };
/**
* @brief Sampling based splitting for parallel multiway-merge routine.
*/
-template<
- bool __stable
- , typename _RAIterIterator
- , typename _Compare
- , typename _DifferenceType>
-void multiway_merge_sampling_splitting(
- _RAIterIterator __seqs_begin,
- _RAIterIterator __seqs_end,
- _DifferenceType __length, _DifferenceType __total_length, _Compare __comp,
- std::vector<std::pair<_DifferenceType, _DifferenceType> > *__pieces)
-{
- typedef typename std::iterator_traits<_RAIterIterator>
- ::value_type::first_type
- _RAIter1;
- typedef typename std::iterator_traits<_RAIter1>::value_type
- _ValueType;
+template<bool __stable,
+ typename _RAIterIterator,
+ typename _Compare,
+ typename _DifferenceType>
+ void
+ multiway_merge_sampling_splitting
+ (_RAIterIterator __seqs_begin,
+ _RAIterIterator __seqs_end,
+ _DifferenceType __length, _DifferenceType __total_length, _Compare __comp,
+ std::vector<std::pair<_DifferenceType, _DifferenceType> > *__pieces)
+ {
+ typedef typename std::iterator_traits<_RAIterIterator>
+ ::value_type::first_type
+ _RAIter1;
+ typedef typename std::iterator_traits<_RAIter1>::value_type
+ _ValueType;
- // __k sequences.
- int __k = static_cast<int>(__seqs_end - __seqs_begin);
+ // __k sequences.
+ int __k = static_cast<int>(__seqs_end - __seqs_begin);
- int __num_threads = omp_get_num_threads();
+ int __num_threads = omp_get_num_threads();
- _DifferenceType __num_samples =
+ _DifferenceType __num_samples =
__gnu_parallel::_Settings::get().merge_oversampling * __num_threads;
- _ValueType* __samples = static_cast<_ValueType*>(
- ::operator new(sizeof(_ValueType) * __k * __num_samples));
- // Sample.
- for (int __s = 0; __s < __k; ++__s)
- for (_DifferenceType __i = 0; __i < __num_samples; ++__i)
- {
- _DifferenceType sample_index =
- static_cast<_DifferenceType>(
- _GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__s])
- * (double(__i + 1) / (__num_samples + 1))
- * (double(__length) / __total_length));
- new(&(__samples[__s * __num_samples + __i]))
+ _ValueType* __samples = static_cast<_ValueType*>
+ (::operator new(sizeof(_ValueType) * __k * __num_samples));
+ // Sample.
+ for (int __s = 0; __s < __k; ++__s)
+ for (_DifferenceType __i = 0; __i < __num_samples; ++__i)
+ {
+ _DifferenceType sample_index =
+ static_cast<_DifferenceType>
+ (_GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__s])
+ * (double(__i + 1) / (__num_samples + 1))
+ * (double(__length) / __total_length));
+ new(&(__samples[__s * __num_samples + __i]))
_ValueType(__seqs_begin[__s].first[sample_index]);
- }
+ }
- // Sort stable or non-stable, depending on value of template parameter
- // "__stable".
- _SamplingSorter<__stable, _ValueType*, _Compare>()(
- __samples, __samples + (__num_samples * __k), __comp);
+ // Sort stable or non-stable, depending on value of template parameter
+ // "__stable".
+ _SamplingSorter<__stable, _ValueType*, _Compare>()
+ (__samples, __samples + (__num_samples * __k), __comp);
- for (int __slab = 0; __slab < __num_threads; ++__slab)
- // For each slab / processor.
- for (int __seq = 0; __seq < __k; ++__seq)
- {
- // For each sequence.
- if (__slab > 0)
- __pieces[__slab][__seq].first =
- std::upper_bound(
- __seqs_begin[__seq].first,
- __seqs_begin[__seq].second,
- __samples[__num_samples * __k * __slab / __num_threads],
- __comp)
+ for (int __slab = 0; __slab < __num_threads; ++__slab)
+ // For each slab / processor.
+ for (int __seq = 0; __seq < __k; ++__seq)
+ {
+ // For each sequence.
+ if (__slab > 0)
+ __pieces[__slab][__seq].first =
+ std::upper_bound
+ (__seqs_begin[__seq].first,
+ __seqs_begin[__seq].second,
+ __samples[__num_samples * __k * __slab / __num_threads],
+ __comp) - __seqs_begin[__seq].first;
+ else
+ // Absolute beginning.
+ __pieces[__slab][__seq].first = 0;
+ if ((__slab + 1) < __num_threads)
+ __pieces[__slab][__seq].second =
+ std::upper_bound
+ (__seqs_begin[__seq].first,
+ __seqs_begin[__seq].second,
+ __samples[__num_samples * __k * (__slab + 1) /
+ __num_threads], __comp)
- __seqs_begin[__seq].first;
- else
- // Absolute beginning.
- __pieces[__slab][__seq].first = 0;
- if ((__slab + 1) < __num_threads)
- __pieces[__slab][__seq].second =
- std::upper_bound(
- __seqs_begin[__seq].first,
- __seqs_begin[__seq].second,
- __samples[__num_samples * __k * (__slab + 1) /
- __num_threads], __comp)
- - __seqs_begin[__seq].first;
- else
+ else
// Absolute end.
- __pieces[__slab][__seq].second
- = _GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__seq]);
- }
+ __pieces[__slab][__seq].second
+ = _GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__seq]);
+ }
::operator delete(__samples);
-}
+ }
/**
* @brief Exact splitting for parallel multiway-merge routine.
*
* None of the passed sequences may be empty.
*/
-template<
- bool __stable
- , typename _RAIterIterator
- , typename _Compare
- , typename _DifferenceType>
-void multiway_merge_exact_splitting(
- _RAIterIterator __seqs_begin,
- _RAIterIterator __seqs_end,
- _DifferenceType __length, _DifferenceType __total_length, _Compare __comp,
- std::vector<std::pair<_DifferenceType, _DifferenceType> > *__pieces)
-{
- typedef typename std::iterator_traits<_RAIterIterator>
- ::value_type::first_type
- _RAIter1;
+template<bool __stable,
+ typename _RAIterIterator,
+ typename _Compare,
+ typename _DifferenceType>
+ void
+ multiway_merge_exact_splitting
+ (_RAIterIterator __seqs_begin,
+ _RAIterIterator __seqs_end,
+ _DifferenceType __length, _DifferenceType __total_length,
+ _Compare __comp,
+ std::vector<std::pair<_DifferenceType, _DifferenceType> > *__pieces)
+ {
+ typedef typename std::iterator_traits<_RAIterIterator>
+ ::value_type::first_type
+ _RAIter1;
- const bool __tight = (__total_length == __length);
+ const bool __tight = (__total_length == __length);
- // __k sequences.
- const int __k = static_cast<int>(__seqs_end - __seqs_begin);
+ // __k sequences.
+ const int __k = static_cast<int>(__seqs_end - __seqs_begin);
- const int __num_threads = omp_get_num_threads();
+ const int __num_threads = omp_get_num_threads();
- // (Settings::multiway_merge_splitting == __gnu_parallel::_Settings::EXACT).
- std::vector<_RAIter1>* __offsets =
+ // (Settings::multiway_merge_splitting == __gnu_parallel::_Settings::EXACT).
+ std::vector<_RAIter1>* __offsets =
new std::vector<_RAIter1>[__num_threads];
- std::vector<
- std::pair<_RAIter1, _RAIter1>
- > __se(__k);
+ std::vector<std::pair<_RAIter1, _RAIter1> > __se(__k);
- copy(__seqs_begin, __seqs_end, __se.begin());
+ copy(__seqs_begin, __seqs_end, __se.begin());
- _DifferenceType* __borders =
+ _DifferenceType* __borders =
new _DifferenceType[__num_threads + 1];
- equally_split(__length, __num_threads, __borders);
+ equally_split(__length, __num_threads, __borders);
- for (int __s = 0; __s < (__num_threads - 1); ++__s)
- {
- __offsets[__s].resize(__k);
- multiseq_partition(
- __se.begin(), __se.end(), __borders[__s + 1],
- __offsets[__s].begin(), __comp);
+ for (int __s = 0; __s < (__num_threads - 1); ++__s)
+ {
+ __offsets[__s].resize(__k);
+ multiseq_partition
+ (__se.begin(), __se.end(), __borders[__s + 1],
+ __offsets[__s].begin(), __comp);
- // Last one also needed and available.
- if (!__tight)
- {
- __offsets[__num_threads - 1].resize(__k);
- multiseq_partition(__se.begin(), __se.end(),
- _DifferenceType(__length),
- __offsets[__num_threads - 1].begin(), __comp);
- }
- }
- delete[] __borders;
+ // Last one also needed and available.
+ if (!__tight)
+ {
+ __offsets[__num_threads - 1].resize(__k);
+ multiseq_partition(__se.begin(), __se.end(),
+ _DifferenceType(__length),
+ __offsets[__num_threads - 1].begin(), __comp);
+ }
+ }
+ delete[] __borders;
- for (int __slab = 0; __slab < __num_threads; ++__slab)
- {
- // For each slab / processor.
- for (int __seq = 0; __seq < __k; ++__seq)
- {
- // For each sequence.
- if (__slab == 0)
- {
- // Absolute beginning.
- __pieces[__slab][__seq].first = 0;
- }
- else
- __pieces[__slab][__seq].first =
+ for (int __slab = 0; __slab < __num_threads; ++__slab)
+ {
+ // For each slab / processor.
+ for (int __seq = 0; __seq < __k; ++__seq)
+ {
+ // For each sequence.
+ if (__slab == 0)
+ {
+ // Absolute beginning.
+ __pieces[__slab][__seq].first = 0;
+ }
+ else
+ __pieces[__slab][__seq].first =
__pieces[__slab - 1][__seq].second;
- if (!__tight || __slab < (__num_threads - 1))
- __pieces[__slab][__seq].second =
+ if (!__tight || __slab < (__num_threads - 1))
+ __pieces[__slab][__seq].second =
__offsets[__slab][__seq] - __seqs_begin[__seq].first;
- else
- {
- // __slab == __num_threads - 1
- __pieces[__slab][__seq].second =
+ else
+ {
+ // __slab == __num_threads - 1
+ __pieces[__slab][__seq].second =
_GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__seq]);
- }
- }
- }
- delete[] __offsets;
-}
+ }
+ }
+ }
+ delete[] __offsets;
+ }
/** @brief Parallel multi-way merge routine.
*
@@ -1279,15 +1262,13 @@
* @param __sentinel Ignored.
* @return End iterator of output sequence.
*/
-template<
- bool __stable,
- bool __sentinels,
- typename _RAIterIterator,
- typename _RAIter3,
- typename _DifferenceTp,
- typename _Splitter,
- typename _Compare
- >
+template<bool __stable,
+ bool __sentinels,
+ typename _RAIterIterator,
+ typename _RAIter3,
+ typename _DifferenceTp,
+ typename _Splitter,
+ typename _Compare>
_RAIter3
parallel_multiway_merge(_RAIterIterator __seqs_begin,
_RAIterIterator __seqs_end,
@@ -1475,45 +1456,43 @@
*/
// multiway_merge
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::sequential_tag)
-{
- typedef _DifferenceTp _DifferenceType;
- _GLIBCXX_CALL(__seqs_end - __seqs_begin)
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::sequential_tag)
+ {
+ typedef _DifferenceTp _DifferenceType;
+ _GLIBCXX_CALL(__seqs_end - __seqs_begin)
- // catch special case: no sequences
- if (__seqs_begin == __seqs_end)
- return __target;
+ // catch special case: no sequences
+ if (__seqs_begin == __seqs_end)
+ return __target;
- // Execute multiway merge *sequentially*.
- return __sequential_multiway_merge
- </* __stable = */ false, /* __sentinels = */ false>
+ // Execute multiway merge *sequentially*.
+ return __sequential_multiway_merge
+ </* __stable = */ false, /* __sentinels = */ false>
(__seqs_begin, __seqs_end, __target,
- *(__seqs_begin->second), __length, __comp);
-}
+ *(__seqs_begin->second), __length, __comp);
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::exact_tag __tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::exact_tag __tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -1543,21 +1522,20 @@
</* __stable = */ false, /* __sentinels = */ false>(
__seqs_begin, __seqs_end, __target, *(__seqs_begin->second),
__length, __comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::sampling_tag __tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::sampling_tag __tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -1588,56 +1566,53 @@
</* __stable = */ false, /* __sentinels = */ false>(
__seqs_begin, __seqs_end,
__target, *(__seqs_begin->second), __length, __comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , parallel_tag __tag = parallel_tag(0))
-{
- return multiway_merge(__seqs_begin, __seqs_end, __target, __length, __comp,
- exact_tag(__tag.__get_num_threads()));
-}
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ parallel_tag __tag = parallel_tag(0))
+ {
+ return multiway_merge(__seqs_begin, __seqs_end, __target, __length,
+ __comp, exact_tag(__tag.__get_num_threads()));
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , default_parallel_tag __tag)
-{
- return multiway_merge(__seqs_begin, __seqs_end, __target, __length, __comp,
- exact_tag(__tag.__get_num_threads()));
-}
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ default_parallel_tag __tag)
+ {
+ return multiway_merge(__seqs_begin, __seqs_end, __target, __length,
+ __comp, exact_tag(__tag.__get_num_threads()));
+ }
// stable_multiway_merge
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::sequential_tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::sequential_tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -1650,21 +1625,20 @@
</* __stable = */ true, /* __sentinels = */ false>
(__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length,
__comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::exact_tag __tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::exact_tag __tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -1695,21 +1669,20 @@
/* __sentinels = */ false>(
__seqs_begin, __seqs_end,
__target, *(__seqs_begin->second), __length, __comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , sampling_tag __tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ sampling_tag __tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -1740,44 +1713,41 @@
</* __stable = */ true, /* __sentinels = */ false>(
__seqs_begin, __seqs_end,
__target, *(__seqs_begin->second), __length, __comp);
-}
+ }
-
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , parallel_tag __tag = parallel_tag(0))
-{
- return stable_multiway_merge(
- __seqs_begin, __seqs_end, __target, __length, __comp,
- exact_tag(__tag.__get_num_threads()));
-}
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ parallel_tag __tag = parallel_tag(0))
+ {
+ return stable_multiway_merge
+ (__seqs_begin, __seqs_end, __target, __length, __comp,
+ exact_tag(__tag.__get_num_threads()));
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , default_parallel_tag __tag)
-{
- return stable_multiway_merge(
- __seqs_begin, __seqs_end, __target, __length, __comp,
- exact_tag(__tag.__get_num_threads()));
-}
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ default_parallel_tag __tag)
+ {
+ return stable_multiway_merge
+ (__seqs_begin, __seqs_end, __target, __length, __comp,
+ exact_tag(__tag.__get_num_threads()));
+ }
/**
* @brief Multiway Merge Frontend.
@@ -1856,18 +1826,17 @@
*/
// multiway_merge_sentinels
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::sequential_tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::sequential_tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -1880,21 +1849,20 @@
</* __stable = */ false, /* __sentinels = */ true>
(__seqs_begin, __seqs_end,
__target, *(__seqs_begin->second), __length, __comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::exact_tag __tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::exact_tag __tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -1925,21 +1893,20 @@
</* __stable = */ false, /* __sentinels = */ true>(
__seqs_begin, __seqs_end,
__target, *(__seqs_begin->second), __length, __comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , sampling_tag __tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ sampling_tag __tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -1969,58 +1936,55 @@
</* __stable = */false, /* __sentinels = */ true>(
__seqs_begin, __seqs_end,
__target, *(__seqs_begin->second), __length, __comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , parallel_tag __tag = parallel_tag(0))
-{
- return multiway_merge_sentinels(
- __seqs_begin, __seqs_end, __target, __length, __comp,
- exact_tag(__tag.__get_num_threads()));
-}
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ parallel_tag __tag = parallel_tag(0))
+ {
+ return multiway_merge_sentinels
+ (__seqs_begin, __seqs_end, __target, __length, __comp,
+ exact_tag(__tag.__get_num_threads()));
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , default_parallel_tag __tag)
-{
- return multiway_merge_sentinels(
- __seqs_begin, __seqs_end, __target, __length, __comp,
- exact_tag(__tag.__get_num_threads()));
-}
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ default_parallel_tag __tag)
+ {
+ return multiway_merge_sentinels
+ (__seqs_begin, __seqs_end, __target, __length, __comp,
+ exact_tag(__tag.__get_num_threads()));
+ }
// stable_multiway_merge_sentinels
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::sequential_tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::sequential_tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -2031,23 +1995,22 @@
// Execute multiway merge *sequentially*.
return __sequential_multiway_merge
</* __stable = */ true, /* __sentinels = */ true>
- (__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length,
- __comp);
-}
+ (__seqs_begin, __seqs_end, __target, *(__seqs_begin->second),
+ __length, __comp);
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , __gnu_parallel::exact_tag __tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ __gnu_parallel::exact_tag __tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -2078,21 +2041,21 @@
</* __stable = */ true, /* __sentinels = */ true>(
__seqs_begin, __seqs_end, __target, *(__seqs_begin->second),
__length, __comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , sampling_tag __tag)
-{
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length,
+ _Compare __comp,
+ sampling_tag __tag)
+ {
typedef _DifferenceTp _DifferenceType;
_GLIBCXX_CALL(__seqs_end - __seqs_begin)
@@ -2123,43 +2086,42 @@
</* __stable = */ true, /* __sentinels = */ true>(
__seqs_begin, __seqs_end,
__target, *(__seqs_begin->second), __length, __comp);
-}
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , parallel_tag __tag = parallel_tag(0))
-{
- return stable_multiway_merge_sentinels(
- __seqs_begin, __seqs_end, __target, __length, __comp,
- exact_tag(__tag.__get_num_threads()));
-}
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length,
+ _Compare __comp,
+ parallel_tag __tag = parallel_tag(0))
+ {
+ return stable_multiway_merge_sentinels
+ (__seqs_begin, __seqs_end, __target, __length, __comp,
+ exact_tag(__tag.__get_num_threads()));
+ }
// public interface
-template<
- typename _RAIterPairIterator
- , typename _RAIterOut
- , typename _DifferenceTp
- , typename _Compare>
-_RAIterOut
-stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
- , _RAIterPairIterator __seqs_end
- , _RAIterOut __target
- , _DifferenceTp __length, _Compare __comp
- , default_parallel_tag __tag)
-{
- return stable_multiway_merge_sentinels(
- __seqs_begin, __seqs_end, __target, __length, __comp,
- exact_tag(__tag.__get_num_threads()));
-}
+template<typename _RAIterPairIterator,
+ typename _RAIterOut,
+ typename _DifferenceTp,
+ typename _Compare>
+ _RAIterOut
+ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin,
+ _RAIterPairIterator __seqs_end,
+ _RAIterOut __target,
+ _DifferenceTp __length, _Compare __comp,
+ default_parallel_tag __tag)
+ {
+ return stable_multiway_merge_sentinels
+ (__seqs_begin, __seqs_end, __target, __length, __comp,
+ exact_tag(__tag.__get_num_threads()));
+ }
}; // namespace __gnu_parallel
Index: include/parallel/losertree.h
===================================================================
--- include/parallel/losertree.h (revision 153902)
+++ include/parallel/losertree.h (working copy)
@@ -40,7 +40,6 @@
namespace __gnu_parallel
{
-
/**
* @brief Guarded loser/tournament tree.
*
@@ -54,339 +53,344 @@
* @param _Compare the comparator to use, defaults to std::less<_Tp>
*/
template<typename _Tp, typename _Compare>
-class _LoserTreeBase
-{
-protected:
- /** @brief Internal representation of a _LoserTree element. */
- struct _Loser
+ class _LoserTreeBase
{
- /** @brief flag, true iff this is a "maximum" __sentinel. */
- bool _M_sup;
- /** @brief __index of the __source __sequence. */
- int _M_source;
- /** @brief _M_key of the element in the _LoserTree. */
- _Tp _M_key;
- };
+ protected:
+ /** @brief Internal representation of a _LoserTree element. */
+ struct _Loser
+ {
+ /** @brief flag, true iff this is a "maximum" __sentinel. */
+ bool _M_sup;
+ /** @brief __index of the __source __sequence. */
+ int _M_source;
+ /** @brief _M_key of the element in the _LoserTree. */
+ _Tp _M_key;
+ };
- unsigned int _M_ik, _M_k, _M_offset;
+ unsigned int _M_ik, _M_k, _M_offset;
- /** log_2{_M_k} */
- unsigned int _M_log_k;
+ /** log_2{_M_k} */
+ unsigned int _M_log_k;
- /** @brief _LoserTree __elements. */
- _Loser* _M_losers;
+ /** @brief _LoserTree __elements. */
+ _Loser* _M_losers;
- /** @brief _Compare to use. */
- _Compare _M_comp;
+ /** @brief _Compare to use. */
+ _Compare _M_comp;
- /**
- * @brief State flag that determines whether the _LoserTree is empty.
- *
- * Only used for building the _LoserTree.
- */
- bool _M_first_insert;
+ /**
+ * @brief State flag that determines whether the _LoserTree is empty.
+ *
+ * Only used for building the _LoserTree.
+ */
+ bool _M_first_insert;
-public:
- /**
- * @brief The constructor.
- *
- * @param __k The number of sequences to merge.
- * @param __comp The comparator to use.
- */
- _LoserTreeBase(unsigned int __k, _Compare __comp)
- : _M_comp(__comp)
- {
- _M_ik = __k;
+ public:
+ /**
+ * @brief The constructor.
+ *
+ * @param __k The number of sequences to merge.
+ * @param __comp The comparator to use.
+ */
+ _LoserTreeBase(unsigned int __k, _Compare __comp)
+ : _M_comp(__comp)
+ {
+ _M_ik = __k;
- // Compute log_2{_M_k} for the _Loser Tree
- _M_log_k = __rd_log2(_M_ik - 1) + 1;
+ // Compute log_2{_M_k} for the _Loser Tree
+ _M_log_k = __rd_log2(_M_ik - 1) + 1;
- // Next greater power of 2.
- _M_k = 1 << _M_log_k;
- _M_offset = _M_k;
+ // Next greater power of 2.
+ _M_k = 1 << _M_log_k;
+ _M_offset = _M_k;
- // Avoid default-constructing _M_losers[]._M_key
- _M_losers
+ // Avoid default-constructing _M_losers[]._M_key
+ _M_losers
= static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser)));
- for (unsigned int __i = _M_ik - 1; __i < _M_k; ++__i)
- _M_losers[__i + _M_k]._M_sup = true;
+ for (unsigned int __i = _M_ik - 1; __i < _M_k; ++__i)
+ _M_losers[__i + _M_k]._M_sup = true;
- _M_first_insert = true;
- }
+ _M_first_insert = true;
+ }
- /**
- * @brief The destructor.
- */
- ~_LoserTreeBase()
- { ::operator delete(_M_losers); }
+ /**
+ * @brief The destructor.
+ */
+ ~_LoserTreeBase()
+ { ::operator delete(_M_losers); }
- /**
- * @brief Initializes the sequence "_M_source" with the element "_M_key".
- *
- * @param _M_key the element to insert
- * @param _M_source __index of the __source __sequence
- * @param _M_sup flag that determines whether the value to insert is an
- * explicit __supremum.
- */
- inline void
- __insert_start(const _Tp& _M_key, int _M_source, bool _M_sup)
- {
- unsigned int __pos = _M_k + _M_source;
+ /**
+ * @brief Initializes the sequence "_M_source" with the element "_M_key".
+ *
+ * @param _M_key the element to insert
+ * @param _M_source __index of the __source __sequence
+ * @param _M_sup flag that determines whether the value to insert is an
+ * explicit __supremum.
+ */
+ void
+ __insert_start(const _Tp& _M_key, int _M_source, bool _M_sup)
+ {
+ unsigned int __pos = _M_k + _M_source;
- if(_M_first_insert)
- {
- // Construct all keys, so we can easily deconstruct them.
- for (unsigned int __i = 0; __i < (2 * _M_k); ++__i)
- new(&(_M_losers[__i]._M_key)) _Tp(_M_key);
- _M_first_insert = false;
- }
- else
- new(&(_M_losers[__pos]._M_key)) _Tp(_M_key);
+ if(_M_first_insert)
+ {
+ // Construct all keys, so we can easily deconstruct them.
+ for (unsigned int __i = 0; __i < (2 * _M_k); ++__i)
+ new(&(_M_losers[__i]._M_key)) _Tp(_M_key);
+ _M_first_insert = false;
+ }
+ else
+ new(&(_M_losers[__pos]._M_key)) _Tp(_M_key);
- _M_losers[__pos]._M_sup = _M_sup;
- _M_losers[__pos]._M_source = _M_source;
- }
+ _M_losers[__pos]._M_sup = _M_sup;
+ _M_losers[__pos]._M_source = _M_source;
+ }
+ /**
+ * @return the index of the sequence with the smallest element.
+ */
+ int __get_min_source()
+ { return _M_losers[0]._M_source; }
+ };
+
/**
- * @return the index of the sequence with the smallest element.
+ * @brief Stable _LoserTree variant.
+ *
+ * Provides the stable implementations of insert_start, __init_winner,
+ * __init and __delete_min_insert.
+ *
+ * Unstable variant is done using partial specialisation below.
*/
- int __get_min_source()
- { return _M_losers[0]._M_source; }
-};
+template<bool __stable/* default == true */, typename _Tp,
+ typename _Compare>
+ class _LoserTree : public _LoserTreeBase<_Tp, _Compare>
+ {
+ typedef _LoserTreeBase<_Tp, _Compare> _Base;
+ using _Base::_M_k;
+ using _Base::_M_losers;
+ using _Base::_M_first_insert;
-/**
- * @brief Stable _LoserTree variant.
- *
- * Provides the stable implementations of insert_start, __init_winner,
- * __init and __delete_min_insert.
- *
- * Unstable variant is done using partial specialisation below.
- */
-template<bool __stable/* default == true */, typename _Tp, typename _Compare>
-class _LoserTree : public _LoserTreeBase<_Tp, _Compare>
-{
- typedef _LoserTreeBase<_Tp, _Compare> Base;
- using Base::_M_k;
- using Base::_M_losers;
- using Base::_M_first_insert;
+ public:
+ _LoserTree(unsigned int __k, _Compare __comp)
+ : _Base::_LoserTreeBase(__k, __comp)
+ { }
-public:
- _LoserTree(unsigned int __k, _Compare __comp)
- : Base::_LoserTreeBase(__k, __comp)
- {}
+ unsigned int
+ __init_winner(unsigned int __root)
+ {
+ if (__root >= _M_k)
+ return __root;
+ else
+ {
+ unsigned int __left = __init_winner (2 * __root);
+ unsigned int __right = __init_winner (2 * __root + 1);
+ if (_M_losers[__right]._M_sup
+ || (!_M_losers[__left]._M_sup
+ && !_M_comp(_M_losers[__right]._M_key,
+ _M_losers[__left]._M_key)))
+ {
+ // Left one is less or equal.
+ _M_losers[__root] = _M_losers[__right];
+ return __left;
+ }
+ else
+ {
+ // Right one is less.
+ _M_losers[__root] = _M_losers[__left];
+ return __right;
+ }
+ }
+ }
- unsigned int
- __init_winner(unsigned int __root)
- {
- if (__root >= _M_k)
- {
- return __root;
- }
- else
- {
- unsigned int __left = __init_winner (2 * __root);
- unsigned int __right = __init_winner (2 * __root + 1);
- if (_M_losers[__right]._M_sup
- || (!_M_losers[__left]._M_sup
- && !_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key)))
- {
- // Left one is less or equal.
- _M_losers[__root] = _M_losers[__right];
- return __left;
- }
- else
- {
- // Right one is less.
- _M_losers[__root] = _M_losers[__left];
- return __right;
- }
- }
- }
+ void __init()
+ { _M_losers[0] = _M_losers[__init_winner(1)]; }
- void __init()
- { _M_losers[0] = _M_losers[__init_winner(1)]; }
-
- /**
- * @brief Delete the smallest element and insert a new element from
- * the previously smallest element's sequence.
- *
- * This implementation is stable.
- */
- // Do not pass a const reference since _M_key will be used as local variable.
- void __delete_min_insert(_Tp _M_key, bool _M_sup)
- {
+ /**
+ * @brief Delete the smallest element and insert a new element from
+ * the previously smallest element's sequence.
+ *
+ * This implementation is stable.
+ */
+ // Do not pass a const reference since _M_key will be used as
+ // local variable.
+ void
+ __delete_min_insert(_Tp _M_key, bool _M_sup)
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- int _M_source = _M_losers[0]._M_source;
- for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
- {
- // The smaller one gets promoted, ties are broken by _M_source.
- if ((_M_sup && (!_M_losers[__pos]._M_sup
- || _M_losers[__pos]._M_source < _M_source))
- || (!_M_sup && !_M_losers[__pos]._M_sup
- && ((_M_comp(_M_losers[__pos]._M_key, _M_key))
- || (!_M_comp(_M_key, _M_losers[__pos]._M_key)
- && _M_losers[__pos]._M_source < _M_source))))
- {
- // The other one is smaller.
- std::swap(_M_losers[__pos]._M_sup, _M_sup);
- std::swap(_M_losers[__pos]._M_source, _M_source);
- std::swap(_M_losers[__pos]._M_key, _M_key);
- }
- }
+ int _M_source = _M_losers[0]._M_source;
+ for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0;
+ __pos /= 2)
+ {
+ // The smaller one gets promoted, ties are broken by _M_source.
+ if ((_M_sup && (!_M_losers[__pos]._M_sup
+ || _M_losers[__pos]._M_source < _M_source))
+ || (!_M_sup && !_M_losers[__pos]._M_sup
+ && ((_M_comp(_M_losers[__pos]._M_key, _M_key))
+ || (!_M_comp(_M_key, _M_losers[__pos]._M_key)
+ && _M_losers[__pos]._M_source < _M_source))))
+ {
+ // The other one is smaller.
+ std::swap(_M_losers[__pos]._M_sup, _M_sup);
+ std::swap(_M_losers[__pos]._M_source, _M_source);
+ std::swap(_M_losers[__pos]._M_key, _M_key);
+ }
+ }
- _M_losers[0]._M_sup = _M_sup;
- _M_losers[0]._M_source = _M_source;
- _M_losers[0]._M_key = _M_key;
- }
-};
+ _M_losers[0]._M_sup = _M_sup;
+ _M_losers[0]._M_source = _M_source;
+ _M_losers[0]._M_key = _M_key;
+ }
+ };
-/**
- * @brief Unstable _LoserTree variant.
- *
- * Stability (non-stable here) is selected with partial specialization.
- */
-template<typename _Tp, typename _Compare>
-class _LoserTree</* __stable == */false, _Tp, _Compare> :
- public _LoserTreeBase<_Tp, _Compare>
-{
- typedef _LoserTreeBase<_Tp, _Compare> Base;
- using Base::_M_log_k;
- using Base::_M_k;
- using Base::_M_losers;
- using Base::_M_first_insert;
-
-public:
- _LoserTree(unsigned int __k, _Compare __comp)
- : Base::_LoserTreeBase(__k, __comp)
- {}
-
/**
- * Computes the winner of the competition at position "__root".
+ * @brief Unstable _LoserTree variant.
*
- * Called recursively (starting at 0) to build the initial tree.
- *
- * @param __root __index of the "game" to start.
+ * Stability (non-stable here) is selected with partial specialization.
*/
- unsigned int
- __init_winner (unsigned int __root)
+template<typename _Tp, typename _Compare>
+ class _LoserTree</* __stable == */false, _Tp, _Compare>
+ : public _LoserTreeBase<_Tp, _Compare>
{
- if (__root >= _M_k)
- {
- return __root;
- }
- else
- {
- unsigned int __left = __init_winner (2 * __root);
- unsigned int __right = __init_winner (2 * __root + 1);
- if (_M_losers[__right]._M_sup
- || (!_M_losers[__left]._M_sup
- && !_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key)))
- {
- // Left one is less or equal.
- _M_losers[__root] = _M_losers[__right];
- return __left;
- }
- else
- {
- // Right one is less.
- _M_losers[__root] = _M_losers[__left];
- return __right;
- }
- }
- }
+ typedef _LoserTreeBase<_Tp, _Compare> _Base;
+ using _Base::_M_log_k;
+ using _Base::_M_k;
+ using _Base::_M_losers;
+ using _Base::_M_first_insert;
- inline void
- __init()
- { _M_losers[0] = _M_losers[__init_winner(1)]; }
+ public:
+ _LoserTree(unsigned int __k, _Compare __comp)
+ : _Base::_LoserTreeBase(__k, __comp)
+ { }
- /**
- * Delete the _M_key smallest element and insert the element _M_key instead.
- *
- * @param _M_key the _M_key to insert
- * @param _M_sup true iff _M_key is an explicitly marked supremum
- */
- // Do not pass a const reference since _M_key will be used as local variable.
- inline void
- __delete_min_insert(_Tp _M_key, bool _M_sup)
- {
+ /**
+ * Computes the winner of the competition at position "__root".
+ *
+ * Called recursively (starting at 0) to build the initial tree.
+ *
+ * @param __root __index of the "game" to start.
+ */
+ unsigned int
+ __init_winner(unsigned int __root)
+ {
+ if (__root >= _M_k)
+ return __root;
+ else
+ {
+ unsigned int __left = __init_winner (2 * __root);
+ unsigned int __right = __init_winner (2 * __root + 1);
+ if (_M_losers[__right]._M_sup
+ || (!_M_losers[__left]._M_sup
+ && !_M_comp(_M_losers[__right]._M_key,
+ _M_losers[__left]._M_key)))
+ {
+ // Left one is less or equal.
+ _M_losers[__root] = _M_losers[__right];
+ return __left;
+ }
+ else
+ {
+ // Right one is less.
+ _M_losers[__root] = _M_losers[__left];
+ return __right;
+ }
+ }
+ }
+
+ void
+ __init()
+ { _M_losers[0] = _M_losers[__init_winner(1)]; }
+
+ /**
+ * Delete the _M_key smallest element and insert the element _M_key
+ * instead.
+ *
+ * @param _M_key the _M_key to insert
+ * @param _M_sup true iff _M_key is an explicitly marked supremum
+ */
+ // Do not pass a const reference since _M_key will be used as local
+ // variable.
+ void
+ __delete_min_insert(_Tp _M_key, bool _M_sup)
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- int _M_source = _M_losers[0]._M_source;
- for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
- {
- // The smaller one gets promoted.
- if (_M_sup || (!_M_losers[__pos]._M_sup
- && _M_comp(_M_losers[__pos]._M_key, _M_key)))
- {
- // The other one is smaller.
- std::swap(_M_losers[__pos]._M_sup, _M_sup);
- std::swap(_M_losers[__pos]._M_source, _M_source);
- std::swap(_M_losers[__pos]._M_key, _M_key);
- }
+ int _M_source = _M_losers[0]._M_source;
+ for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0;
+ __pos /= 2)
+ {
+ // The smaller one gets promoted.
+ if (_M_sup || (!_M_losers[__pos]._M_sup
+ && _M_comp(_M_losers[__pos]._M_key, _M_key)))
+ {
+ // The other one is smaller.
+ std::swap(_M_losers[__pos]._M_sup, _M_sup);
+ std::swap(_M_losers[__pos]._M_source, _M_source);
+ std::swap(_M_losers[__pos]._M_key, _M_key);
+ }
+ }
+
+ _M_losers[0]._M_sup = _M_sup;
+ _M_losers[0]._M_source = _M_source;
+ _M_losers[0]._M_key = _M_key;
}
+ };
- _M_losers[0]._M_sup = _M_sup;
- _M_losers[0]._M_source = _M_source;
- _M_losers[0]._M_key = _M_key;
- }
-};
-
-
/**
* @brief Base class of _Loser Tree implementation using pointers.
*/
template<typename _Tp, typename _Compare>
-class _LoserTreePointerBase
-{
-protected:
- /** @brief Internal representation of _LoserTree __elements. */
- struct _Loser
+ class _LoserTreePointerBase
{
- bool _M_sup;
- int _M_source;
- const _Tp* _M_keyp;
- };
+ protected:
+ /** @brief Internal representation of _LoserTree __elements. */
+ struct _Loser
+ {
+ bool _M_sup;
+ int _M_source;
+ const _Tp* _M_keyp;
+ };
- unsigned int _M_ik, _M_k, _M_offset;
- _Loser* _M_losers;
- _Compare _M_comp;
+ unsigned int _M_ik, _M_k, _M_offset;
+ _Loser* _M_losers;
+ _Compare _M_comp;
-public:
- _LoserTreePointerBase(unsigned int __k, _Compare __comp = std::less<_Tp>())
+ public:
+ _LoserTreePointerBase(unsigned int __k,
+ _Compare __comp = std::less<_Tp>())
: _M_comp(__comp)
- {
- _M_ik = __k;
+ {
+ _M_ik = __k;
- // Next greater power of 2.
- _M_k = 1 << (__rd_log2(_M_ik - 1) + 1);
- _M_offset = _M_k;
- _M_losers = new _Loser[_M_k * 2];
- for (unsigned int __i = _M_ik - 1; __i < _M_k; __i++)
- _M_losers[__i + _M_k]._M_sup = true;
- }
+ // Next greater power of 2.
+ _M_k = 1 << (__rd_log2(_M_ik - 1) + 1);
+ _M_offset = _M_k;
+ _M_losers = new _Loser[_M_k * 2];
+ for (unsigned int __i = _M_ik - 1; __i < _M_k; __i++)
+ _M_losers[__i + _M_k]._M_sup = true;
+ }
- ~_LoserTreePointerBase()
- { ::operator delete[](_M_losers); }
+ ~_LoserTreePointerBase()
+ { ::operator delete[](_M_losers); }
- int __get_min_source()
- { return _M_losers[0]._M_source; }
+ int __get_min_source()
+ { return _M_losers[0]._M_source; }
- void __insert_start(const _Tp& _M_key, int _M_source, bool _M_sup)
- {
- unsigned int __pos = _M_k + _M_source;
+ void __insert_start(const _Tp& _M_key, int _M_source, bool _M_sup)
+ {
+ unsigned int __pos = _M_k + _M_source;
- _M_losers[__pos]._M_sup = _M_sup;
- _M_losers[__pos]._M_source = _M_source;
- _M_losers[__pos]._M_keyp = &_M_key;
- }
-};
+ _M_losers[__pos]._M_sup = _M_sup;
+ _M_losers[__pos]._M_source = _M_source;
+ _M_losers[__pos]._M_keyp = &_M_key;
+ }
+ };
/**
* @brief Stable _LoserTree implementation.
@@ -394,80 +398,79 @@
* The unstable variant is implemented using partial instantiation below.
*/
template<bool __stable/* default == true */, typename _Tp, typename _Compare>
-class _LoserTreePointer : public _LoserTreePointerBase<_Tp, _Compare>
-{
- typedef _LoserTreePointerBase<_Tp, _Compare> Base;
- using Base::_M_k;
- using Base::_M_losers;
+ class _LoserTreePointer
+ : public _LoserTreePointerBase<_Tp, _Compare>
+ {
+ typedef _LoserTreePointerBase<_Tp, _Compare> _Base;
+ using _Base::_M_k;
+ using _Base::_M_losers;
-public:
- _LoserTreePointer(unsigned int __k, _Compare __comp = std::less<_Tp>())
- : Base::_LoserTreePointerBase(__k, __comp)
- {}
+ public:
+ _LoserTreePointer(unsigned int __k, _Compare __comp = std::less<_Tp>())
+ : _Base::_LoserTreePointerBase(__k, __comp)
+ { }
- unsigned int
- __init_winner(unsigned int __root)
- {
- if (__root >= _M_k)
- {
- return __root;
- }
- else
- {
- unsigned int __left = __init_winner (2 * __root);
- unsigned int __right = __init_winner (2 * __root + 1);
- if (_M_losers[__right]._M_sup
- || (!_M_losers[__left]._M_sup
- && !_M_comp(*_M_losers[__right]._M_keyp,
- *_M_losers[__left]._M_keyp)))
- {
- // Left one is less or equal.
- _M_losers[__root] = _M_losers[__right];
- return __left;
- }
- else
- {
- // Right one is less.
- _M_losers[__root] = _M_losers[__left];
- return __right;
- }
- }
- }
+ unsigned int
+ __init_winner(unsigned int __root)
+ {
+ if (__root >= _M_k)
+ return __root;
+ else
+ {
+ unsigned int __left = __init_winner (2 * __root);
+ unsigned int __right = __init_winner (2 * __root + 1);
+ if (_M_losers[__right]._M_sup
+ || (!_M_losers[__left]._M_sup
+ && !_M_comp(*_M_losers[__right]._M_keyp,
+ *_M_losers[__left]._M_keyp)))
+ {
+ // Left one is less or equal.
+ _M_losers[__root] = _M_losers[__right];
+ return __left;
+ }
+ else
+ {
+ // Right one is less.
+ _M_losers[__root] = _M_losers[__left];
+ return __right;
+ }
+ }
+ }
- void __init()
- { _M_losers[0] = _M_losers[__init_winner(1)]; }
+ void __init()
+ { _M_losers[0] = _M_losers[__init_winner(1)]; }
- void __delete_min_insert(const _Tp& _M_key, bool _M_sup)
- {
+ void __delete_min_insert(const _Tp& _M_key, bool _M_sup)
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- const _Tp* _M_keyp = &_M_key;
- int _M_source = _M_losers[0]._M_source;
- for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
- {
- // The smaller one gets promoted, ties are broken by _M_source.
- if ((_M_sup && (!_M_losers[__pos]._M_sup ||
- _M_losers[__pos]._M_source < _M_source)) ||
+ const _Tp* _M_keyp = &_M_key;
+ int _M_source = _M_losers[0]._M_source;
+ for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
+ {
+ // The smaller one gets promoted, ties are broken by _M_source.
+ if ((_M_sup && (!_M_losers[__pos]._M_sup ||
+ _M_losers[__pos]._M_source < _M_source)) ||
(!_M_sup && !_M_losers[__pos]._M_sup &&
- ((_M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)) ||
+ ((_M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)) ||
(!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp)
- && _M_losers[__pos]._M_source < _M_source))))
- {
- // The other one is smaller.
- std::swap(_M_losers[__pos]._M_sup, _M_sup);
- std::swap(_M_losers[__pos]._M_source, _M_source);
- std::swap(_M_losers[__pos]._M_keyp, _M_keyp);
- }
- }
+ && _M_losers[__pos]._M_source < _M_source))))
+ {
+ // The other one is smaller.
+ std::swap(_M_losers[__pos]._M_sup, _M_sup);
+ std::swap(_M_losers[__pos]._M_source, _M_source);
+ std::swap(_M_losers[__pos]._M_keyp, _M_keyp);
+ }
+ }
- _M_losers[0]._M_sup = _M_sup;
- _M_losers[0]._M_source = _M_source;
- _M_losers[0]._M_keyp = _M_keyp;
- }
-};
+ _M_losers[0]._M_sup = _M_sup;
+ _M_losers[0]._M_source = _M_source;
+ _M_losers[0]._M_keyp = _M_keyp;
+ }
+ };
/**
* @brief Unstable _LoserTree implementation.
@@ -475,77 +478,76 @@
* The stable variant is above.
*/
template<typename _Tp, typename _Compare>
-class _LoserTreePointer</* __stable == */false, _Tp, _Compare> :
- public _LoserTreePointerBase<_Tp, _Compare>
-{
- typedef _LoserTreePointerBase<_Tp, _Compare> Base;
- using Base::_M_k;
- using Base::_M_losers;
+ class _LoserTreePointer</* __stable == */false, _Tp, _Compare>
+ : public _LoserTreePointerBase<_Tp, _Compare>
+ {
+ typedef _LoserTreePointerBase<_Tp, _Compare> _Base;
+ using _Base::_M_k;
+ using _Base::_M_losers;
-public:
- _LoserTreePointer(unsigned int __k, _Compare __comp = std::less<_Tp>())
- : Base::_LoserTreePointerBase(__k, __comp)
- {}
+ public:
+ _LoserTreePointer(unsigned int __k, _Compare __comp = std::less<_Tp>())
+ : _Base::_LoserTreePointerBase(__k, __comp)
+ { }
- unsigned int
- __init_winner(unsigned int __root)
- {
- if (__root >= _M_k)
- {
- return __root;
- }
- else
- {
- unsigned int __left = __init_winner (2 * __root);
- unsigned int __right = __init_winner (2 * __root + 1);
- if (_M_losers[__right]._M_sup
+ unsigned int
+ __init_winner(unsigned int __root)
+ {
+ if (__root >= _M_k)
+ return __root;
+ else
+ {
+ unsigned int __left = __init_winner (2 * __root);
+ unsigned int __right = __init_winner (2 * __root + 1);
+ if (_M_losers[__right]._M_sup
|| (!_M_losers[__left]._M_sup
- && !_M_comp(*_M_losers[__right]._M_keyp,
- *_M_losers[__left]._M_keyp)))
- {
- // Left one is less or equal.
- _M_losers[__root] = _M_losers[__right];
- return __left;
- }
- else
- {
- // Right one is less.
- _M_losers[__root] = _M_losers[__left];
- return __right;
- }
- }
- }
+ && !_M_comp(*_M_losers[__right]._M_keyp,
+ *_M_losers[__left]._M_keyp)))
+ {
+ // Left one is less or equal.
+ _M_losers[__root] = _M_losers[__right];
+ return __left;
+ }
+ else
+ {
+ // Right one is less.
+ _M_losers[__root] = _M_losers[__left];
+ return __right;
+ }
+ }
+ }
- void __init()
- { _M_losers[0] = _M_losers[__init_winner(1)]; }
+ void __init()
+ { _M_losers[0] = _M_losers[__init_winner(1)]; }
- void __delete_min_insert(const _Tp& _M_key, bool _M_sup)
- {
+ void __delete_min_insert(const _Tp& _M_key, bool _M_sup)
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- const _Tp* _M_keyp = &_M_key;
- int _M_source = _M_losers[0]._M_source;
- for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
- {
- // The smaller one gets promoted.
- if (_M_sup || (!_M_losers[__pos]._M_sup
- && _M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)))
- {
- // The other one is smaller.
- std::swap(_M_losers[__pos]._M_sup, _M_sup);
- std::swap(_M_losers[__pos]._M_source, _M_source);
- std::swap(_M_losers[__pos]._M_keyp, _M_keyp);
- }
- }
+ const _Tp* _M_keyp = &_M_key;
+ int _M_source = _M_losers[0]._M_source;
+ for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0;
+ __pos /= 2)
+ {
+ // The smaller one gets promoted.
+ if (_M_sup || (!_M_losers[__pos]._M_sup
+ && _M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)))
+ {
+ // The other one is smaller.
+ std::swap(_M_losers[__pos]._M_sup, _M_sup);
+ std::swap(_M_losers[__pos]._M_source, _M_source);
+ std::swap(_M_losers[__pos]._M_keyp, _M_keyp);
+ }
+ }
- _M_losers[0]._M_sup = _M_sup;
- _M_losers[0]._M_source = _M_source;
- _M_losers[0]._M_keyp = _M_keyp;
- }
-};
+ _M_losers[0]._M_sup = _M_sup;
+ _M_losers[0]._M_source = _M_source;
+ _M_losers[0]._M_keyp = _M_keyp;
+ }
+ };
/** @brief Base class for unguarded _LoserTree implementation.
*
@@ -558,63 +560,62 @@
* This is a very fast variant.
*/
template<typename _Tp, typename _Compare>
-class _LoserTreeUnguardedBase
-{
-protected:
- struct _Loser
+ class _LoserTreeUnguardedBase
{
- int _M_source;
- _Tp _M_key;
- };
+ protected:
+ struct _Loser
+ {
+ int _M_source;
+ _Tp _M_key;
+ };
- unsigned int _M_ik, _M_k, _M_offset;
- _Loser* _M_losers;
- _Compare _M_comp;
+ unsigned int _M_ik, _M_k, _M_offset;
+ _Loser* _M_losers;
+ _Compare _M_comp;
-public:
- inline
- _LoserTreeUnguardedBase(unsigned int __k, const _Tp _sentinel,
- _Compare __comp = std::less<_Tp>())
+ public:
+ _LoserTreeUnguardedBase(unsigned int __k, const _Tp _sentinel,
+ _Compare __comp = std::less<_Tp>())
: _M_comp(__comp)
- {
- _M_ik = __k;
+ {
+ _M_ik = __k;
- // Next greater power of 2.
- _M_k = 1 << (__rd_log2(_M_ik - 1) + 1);
- _M_offset = _M_k;
- // Avoid default-constructing _M_losers[]._M_key
- _M_losers
+ // Next greater power of 2.
+ _M_k = 1 << (__rd_log2(_M_ik - 1) + 1);
+ _M_offset = _M_k;
+ // Avoid default-constructing _M_losers[]._M_key
+ _M_losers
= static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser)));
- for (unsigned int __i = _M_k + _M_ik - 1; __i < (2 * _M_k); ++__i)
- {
- _M_losers[__i]._M_key = _sentinel;
- _M_losers[__i]._M_source = -1;
- }
- }
+ for (unsigned int __i = _M_k + _M_ik - 1; __i < (2 * _M_k); ++__i)
+ {
+ _M_losers[__i]._M_key = _sentinel;
+ _M_losers[__i]._M_source = -1;
+ }
+ }
- inline ~_LoserTreeUnguardedBase()
- { ::operator delete(_M_losers); }
+ ~_LoserTreeUnguardedBase()
+ { ::operator delete(_M_losers); }
- inline int
- __get_min_source()
- {
+ int
+ __get_min_source()
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- return _M_losers[0]._M_source;
- }
+ return _M_losers[0]._M_source;
+ }
- inline void
- __insert_start(const _Tp& _M_key, int _M_source, bool)
- {
- unsigned int __pos = _M_k + _M_source;
+ void
+ __insert_start(const _Tp& _M_key, int _M_source, bool)
+ {
+ unsigned int __pos = _M_k + _M_source;
- new(&(_M_losers[__pos]._M_key)) _Tp(_M_key);
- _M_losers[__pos]._M_source = _M_source;
- }
-};
+ new(&(_M_losers[__pos]._M_key)) _Tp(_M_key);
+ _M_losers[__pos]._M_source = _M_source;
+ }
+ };
/**
* @brief Stable implementation of unguarded _LoserTree.
@@ -622,82 +623,83 @@
* Unstable variant is selected below with partial specialization.
*/
template<bool __stable/* default == true */, typename _Tp, typename _Compare>
-class _LoserTreeUnguarded : public _LoserTreeUnguardedBase<_Tp, _Compare>
-{
- typedef _LoserTreeUnguardedBase<_Tp, _Compare> Base;
- using Base::_M_k;
- using Base::_M_losers;
+ class _LoserTreeUnguarded
+ : public _LoserTreeUnguardedBase<_Tp, _Compare>
+ {
+ typedef _LoserTreeUnguardedBase<_Tp, _Compare> _Base;
+ using _Base::_M_k;
+ using _Base::_M_losers;
public:
- _LoserTreeUnguarded(unsigned int __k, const _Tp _sentinel,
- _Compare __comp = std::less<_Tp>())
- : Base::_LoserTreeUnguardedBase(__k, _sentinel, __comp)
- {}
+ _LoserTreeUnguarded(unsigned int __k, const _Tp _sentinel,
+ _Compare __comp = std::less<_Tp>())
+ : _Base::_LoserTreeUnguardedBase(__k, _sentinel, __comp)
+ { }
- unsigned int
- __init_winner(unsigned int __root)
- {
- if (__root >= _M_k)
- {
- return __root;
- }
- else
- {
- unsigned int __left = __init_winner (2 * __root);
- unsigned int __right = __init_winner (2 * __root + 1);
- if (!_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key))
- {
- // Left one is less or equal.
- _M_losers[__root] = _M_losers[__right];
- return __left;
- }
- else
- {
- // Right one is less.
- _M_losers[__root] = _M_losers[__left];
- return __right;
- }
- }
- }
+ unsigned int
+ __init_winner(unsigned int __root)
+ {
+ if (__root >= _M_k)
+ return __root;
+ else
+ {
+ unsigned int __left = __init_winner (2 * __root);
+ unsigned int __right = __init_winner (2 * __root + 1);
+ if (!_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key))
+ {
+ // Left one is less or equal.
+ _M_losers[__root] = _M_losers[__right];
+ return __left;
+ }
+ else
+ {
+ // Right one is less.
+ _M_losers[__root] = _M_losers[__left];
+ return __right;
+ }
+ }
+ }
- inline void
- __init()
- {
- _M_losers[0] = _M_losers[__init_winner(1)];
-
+ void
+ __init()
+ {
+ _M_losers[0] = _M_losers[__init_winner(1)];
+
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top at the beginning (0 sequences!)
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top at the beginning
+ // (0 sequences!)
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- }
+ }
- // Do not pass a const reference since _M_key will be used as local variable.
- inline void
- __delete_min_insert(_Tp _M_key, bool)
- {
+ // Do not pass a const reference since _M_key will be used as
+ // local variable.
+ void
+ __delete_min_insert(_Tp _M_key, bool)
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- int _M_source = _M_losers[0]._M_source;
- for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
- {
- // The smaller one gets promoted, ties are broken by _M_source.
- if (_M_comp(_M_losers[__pos]._M_key, _M_key)
+ int _M_source = _M_losers[0]._M_source;
+ for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
+ {
+ // The smaller one gets promoted, ties are broken by _M_source.
+ if (_M_comp(_M_losers[__pos]._M_key, _M_key)
|| (!_M_comp(_M_key, _M_losers[__pos]._M_key)
&& _M_losers[__pos]._M_source < _M_source))
- {
- // The other one is smaller.
- std::swap(_M_losers[__pos]._M_source, _M_source);
- std::swap(_M_losers[__pos]._M_key, _M_key);
- }
- }
+ {
+ // The other one is smaller.
+ std::swap(_M_losers[__pos]._M_source, _M_source);
+ std::swap(_M_losers[__pos]._M_key, _M_key);
+ }
+ }
- _M_losers[0]._M_source = _M_source;
- _M_losers[0]._M_key = _M_key;
- }
-};
+ _M_losers[0]._M_source = _M_source;
+ _M_losers[0]._M_key = _M_key;
+ }
+ };
/**
* @brief Non-Stable implementation of unguarded _LoserTree.
@@ -705,88 +707,88 @@
* Stable implementation is above.
*/
template<typename _Tp, typename _Compare>
-class _LoserTreeUnguarded</* __stable == */false, _Tp, _Compare> :
- public _LoserTreeUnguardedBase<_Tp, _Compare>
-{
- typedef _LoserTreeUnguardedBase<_Tp, _Compare> Base;
- using Base::_M_k;
- using Base::_M_losers;
+ class _LoserTreeUnguarded</* __stable == */false, _Tp, _Compare>
+ : public _LoserTreeUnguardedBase<_Tp, _Compare>
+ {
+ typedef _LoserTreeUnguardedBase<_Tp, _Compare> _Base;
+ using _Base::_M_k;
+ using _Base::_M_losers;
public:
- _LoserTreeUnguarded(unsigned int __k, const _Tp _sentinel,
- _Compare __comp = std::less<_Tp>())
- : Base::_LoserTreeUnguardedBase(__k, _sentinel, __comp)
- {}
+ _LoserTreeUnguarded(unsigned int __k, const _Tp _sentinel,
+ _Compare __comp = std::less<_Tp>())
+ : _Base::_LoserTreeUnguardedBase(__k, _sentinel, __comp)
+ { }
- unsigned int
- __init_winner (unsigned int __root)
- {
- if (__root >= _M_k)
- {
- return __root;
- }
- else
- {
- unsigned int __left = __init_winner (2 * __root);
- unsigned int __right = __init_winner (2 * __root + 1);
+ unsigned int
+ __init_winner(unsigned int __root)
+ {
+ if (__root >= _M_k)
+ return __root;
+ else
+ {
+ unsigned int __left = __init_winner (2 * __root);
+ unsigned int __right = __init_winner (2 * __root + 1);
#if _GLIBCXX_ASSERTIONS
- // If __left one is sentinel then __right one must be, too.
- if (_M_losers[__left]._M_source == -1)
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[__right]._M_source == -1);
+ // If __left one is sentinel then __right one must be, too.
+ if (_M_losers[__left]._M_source == -1)
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[__right]._M_source == -1);
#endif
- if (!_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key))
- {
- // Left one is less or equal.
- _M_losers[__root] = _M_losers[__right];
- return __left;
- }
- else
- {
- // Right one is less.
- _M_losers[__root] = _M_losers[__left];
- return __right;
- }
- }
- }
+ if (!_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key))
+ {
+ // Left one is less or equal.
+ _M_losers[__root] = _M_losers[__right];
+ return __left;
+ }
+ else
+ {
+ // Right one is less.
+ _M_losers[__root] = _M_losers[__left];
+ return __right;
+ }
+ }
+ }
- inline void
- __init()
- {
- _M_losers[0] = _M_losers[__init_winner(1)];
+ void
+ __init()
+ {
+ _M_losers[0] = _M_losers[__init_winner(1)];
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top at the beginning (0 sequences!)
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top at the beginning
+ // (0 sequences!)
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- }
+ }
- // Do not pass a const reference since _M_key will be used as local variable.
- inline void
- __delete_min_insert(_Tp _M_key, bool)
- {
+ // Do not pass a const reference since _M_key will be used as
+ // local variable.
+ void
+ __delete_min_insert(_Tp _M_key, bool)
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- int _M_source = _M_losers[0]._M_source;
- for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
- {
- // The smaller one gets promoted.
- if (_M_comp(_M_losers[__pos]._M_key, _M_key))
- {
- // The other one is smaller.
- std::swap(_M_losers[__pos]._M_source, _M_source);
- std::swap(_M_losers[__pos]._M_key, _M_key);
- }
- }
+ int _M_source = _M_losers[0]._M_source;
+ for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
+ {
+ // The smaller one gets promoted.
+ if (_M_comp(_M_losers[__pos]._M_key, _M_key))
+ {
+ // The other one is smaller.
+ std::swap(_M_losers[__pos]._M_source, _M_source);
+ std::swap(_M_losers[__pos]._M_key, _M_key);
+ }
+ }
- _M_losers[0]._M_source = _M_source;
- _M_losers[0]._M_key = _M_key;
- }
-};
+ _M_losers[0]._M_source = _M_source;
+ _M_losers[0]._M_key = _M_key;
+ }
+ };
/** @brief Unguarded loser tree, keeping only pointers to the
* elements in the tree structure.
@@ -795,63 +797,62 @@
* run empty. This is a very fast variant.
*/
template<typename _Tp, typename _Compare>
-class LoserTreePointerUnguardedBase
-{
-protected:
- struct _Loser
+ class LoserTreePointerUnguardedBase
{
- int _M_source;
- const _Tp* _M_keyp;
- };
+ protected:
+ struct _Loser
+ {
+ int _M_source;
+ const _Tp* _M_keyp;
+ };
- unsigned int _M_ik, _M_k, _M_offset;
- _Loser* _M_losers;
- _Compare _M_comp;
+ unsigned int _M_ik, _M_k, _M_offset;
+ _Loser* _M_losers;
+ _Compare _M_comp;
-public:
+ public:
- inline
- LoserTreePointerUnguardedBase(unsigned int __k, const _Tp& _sentinel,
- _Compare __comp = std::less<_Tp>())
+ LoserTreePointerUnguardedBase(unsigned int __k, const _Tp& _sentinel,
+ _Compare __comp = std::less<_Tp>())
: _M_comp(__comp)
- {
- _M_ik = __k;
+ {
+ _M_ik = __k;
- // Next greater power of 2.
- _M_k = 1 << (__rd_log2(_M_ik - 1) + 1);
- _M_offset = _M_k;
- // Avoid default-constructing _M_losers[]._M_key
- _M_losers = new _Loser[2 * _M_k];
+ // Next greater power of 2.
+ _M_k = 1 << (__rd_log2(_M_ik - 1) + 1);
+ _M_offset = _M_k;
+ // Avoid default-constructing _M_losers[]._M_key
+ _M_losers = new _Loser[2 * _M_k];
- for (unsigned int __i = _M_k + _M_ik - 1; __i < (2 * _M_k); ++__i)
- {
- _M_losers[__i]._M_keyp = &_sentinel;
- _M_losers[__i]._M_source = -1;
- }
- }
+ for (unsigned int __i = _M_k + _M_ik - 1; __i < (2 * _M_k); ++__i)
+ {
+ _M_losers[__i]._M_keyp = &_sentinel;
+ _M_losers[__i]._M_source = -1;
+ }
+ }
- inline ~LoserTreePointerUnguardedBase()
- { delete[] _M_losers; }
+ ~LoserTreePointerUnguardedBase()
+ { delete[] _M_losers; }
- inline int
- __get_min_source()
- {
+ int
+ __get_min_source()
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- return _M_losers[0]._M_source;
- }
+ return _M_losers[0]._M_source;
+ }
- inline void
- __insert_start(const _Tp& _M_key, int _M_source, bool)
- {
- unsigned int __pos = _M_k + _M_source;
+ void
+ __insert_start(const _Tp& _M_key, int _M_source, bool)
+ {
+ unsigned int __pos = _M_k + _M_source;
- _M_losers[__pos]._M_keyp = &_M_key;
- _M_losers[__pos]._M_source = _M_source;
- }
-};
+ _M_losers[__pos]._M_keyp = &_M_key;
+ _M_losers[__pos]._M_source = _M_source;
+ }
+ };
/**
* @brief Stable unguarded _LoserTree variant storing pointers.
@@ -859,83 +860,83 @@
* Unstable variant is implemented below using partial specialization.
*/
template<bool __stable/* default == true */, typename _Tp, typename _Compare>
-class _LoserTreePointerUnguarded :
- public LoserTreePointerUnguardedBase<_Tp, _Compare>
-{
- typedef LoserTreePointerUnguardedBase<_Tp, _Compare> Base;
- using Base::_M_k;
- using Base::_M_losers;
+ class _LoserTreePointerUnguarded
+ : public LoserTreePointerUnguardedBase<_Tp, _Compare>
+ {
+ typedef LoserTreePointerUnguardedBase<_Tp, _Compare> _Base;
+ using _Base::_M_k;
+ using _Base::_M_losers;
-public:
- _LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel,
- _Compare __comp = std::less<_Tp>())
- : Base::LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
- {}
+ public:
+ _LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel,
+ _Compare __comp = std::less<_Tp>())
+ : _Base::LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
+ { }
- unsigned int
- __init_winner(unsigned int __root)
- {
- if (__root >= _M_k)
- {
- return __root;
- }
- else
- {
- unsigned int __left = __init_winner (2 * __root);
- unsigned int __right = __init_winner (2 * __root + 1);
- if (!_M_comp(*_M_losers[__right]._M_keyp, *_M_losers[__left]._M_keyp))
- {
- // Left one is less or equal.
- _M_losers[__root] = _M_losers[__right];
- return __left;
- }
- else
- {
- // Right one is less.
- _M_losers[__root] = _M_losers[__left];
- return __right;
- }
- }
- }
+ unsigned int
+ __init_winner(unsigned int __root)
+ {
+ if (__root >= _M_k)
+ return __root;
+ else
+ {
+ unsigned int __left = __init_winner (2 * __root);
+ unsigned int __right = __init_winner (2 * __root + 1);
+ if (!_M_comp(*_M_losers[__right]._M_keyp,
+ *_M_losers[__left]._M_keyp))
+ {
+ // Left one is less or equal.
+ _M_losers[__root] = _M_losers[__right];
+ return __left;
+ }
+ else
+ {
+ // Right one is less.
+ _M_losers[__root] = _M_losers[__left];
+ return __right;
+ }
+ }
+ }
+
+ void
+ __init()
+ {
+ _M_losers[0] = _M_losers[__init_winner(1)];
- inline void
- __init()
- {
- _M_losers[0] = _M_losers[__init_winner(1)];
-
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top at the beginning (0 sequences!)
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top at the beginning
+ // (0 sequences!)
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- }
+ }
- inline void
- __delete_min_insert(const _Tp& _M_key, bool _M_sup)
- {
+ void
+ __delete_min_insert(const _Tp& _M_key, bool _M_sup)
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- const _Tp* _M_keyp = &_M_key;
- int _M_source = _M_losers[0]._M_source;
- for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
- {
- // The smaller one gets promoted, ties are broken by _M_source.
- if (_M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)
- || (!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp)
- && _M_losers[__pos]._M_source < _M_source))
- {
- // The other one is smaller.
- std::swap(_M_losers[__pos]._M_source, _M_source);
- std::swap(_M_losers[__pos]._M_keyp, _M_keyp);
- }
- }
+ const _Tp* _M_keyp = &_M_key;
+ int _M_source = _M_losers[0]._M_source;
+ for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
+ {
+ // The smaller one gets promoted, ties are broken by _M_source.
+ if (_M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)
+ || (!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp)
+ && _M_losers[__pos]._M_source < _M_source))
+ {
+ // The other one is smaller.
+ std::swap(_M_losers[__pos]._M_source, _M_source);
+ std::swap(_M_losers[__pos]._M_keyp, _M_keyp);
+ }
+ }
- _M_losers[0]._M_source = _M_source;
- _M_losers[0]._M_keyp = _M_keyp;
- }
-};
+ _M_losers[0]._M_source = _M_source;
+ _M_losers[0]._M_keyp = _M_keyp;
+ }
+ };
/**
* @brief Unstable unguarded _LoserTree variant storing pointers.
@@ -943,89 +944,88 @@
* Stable variant is above.
*/
template<typename _Tp, typename _Compare>
-class _LoserTreePointerUnguarded</* __stable == */false, _Tp, _Compare> :
- public LoserTreePointerUnguardedBase<_Tp, _Compare>
-{
- typedef LoserTreePointerUnguardedBase<_Tp, _Compare> Base;
- using Base::_M_k;
- using Base::_M_losers;
+ class _LoserTreePointerUnguarded</* __stable == */false, _Tp, _Compare>
+ : public LoserTreePointerUnguardedBase<_Tp, _Compare>
+ {
+ typedef LoserTreePointerUnguardedBase<_Tp, _Compare> _Base;
+ using _Base::_M_k;
+ using _Base::_M_losers;
public:
- _LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel,
- _Compare __comp = std::less<_Tp>())
- : Base::LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
- {}
+ _LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel,
+ _Compare __comp = std::less<_Tp>())
+ : _Base::LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
+ { }
- unsigned int
- __init_winner(unsigned int __root)
- {
- if (__root >= _M_k)
- {
- return __root;
- }
- else
- {
- unsigned int __left = __init_winner (2 * __root);
- unsigned int __right = __init_winner (2 * __root + 1);
+ unsigned int
+ __init_winner(unsigned int __root)
+ {
+ if (__root >= _M_k)
+ return __root;
+ else
+ {
+ unsigned int __left = __init_winner (2 * __root);
+ unsigned int __right = __init_winner (2 * __root + 1);
#if _GLIBCXX_ASSERTIONS
- // If __left one is sentinel then __right one must be, too.
- if (_M_losers[__left]._M_source == -1)
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[__right]._M_source == -1);
+ // If __left one is sentinel then __right one must be, too.
+ if (_M_losers[__left]._M_source == -1)
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[__right]._M_source == -1);
#endif
- if (!_M_comp(*_M_losers[__right]._M_keyp, *_M_losers[__left]._M_keyp))
- {
- // Left one is less or equal.
- _M_losers[__root] = _M_losers[__right];
- return __left;
- }
- else
- {
- // Right one is less.
- _M_losers[__root] = _M_losers[__left];
- return __right;
- }
- }
- }
+ if (!_M_comp(*_M_losers[__right]._M_keyp,
+ *_M_losers[__left]._M_keyp))
+ {
+ // Left one is less or equal.
+ _M_losers[__root] = _M_losers[__right];
+ return __left;
+ }
+ else
+ {
+ // Right one is less.
+ _M_losers[__root] = _M_losers[__left];
+ return __right;
+ }
+ }
+ }
- inline void
- __init()
- {
- _M_losers[0] = _M_losers[__init_winner(1)];
+ void
+ __init()
+ {
+ _M_losers[0] = _M_losers[__init_winner(1)];
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top at the beginning (0 sequences!)
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top at the beginning
+ // (0 sequences!)
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- }
+ }
- inline void
- __delete_min_insert(const _Tp& _M_key, bool _M_sup)
- {
+ void
+ __delete_min_insert(const _Tp& _M_key, bool _M_sup)
+ {
#if _GLIBCXX_ASSERTIONS
- // no dummy sequence can ever be at the top!
- _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
+ // no dummy sequence can ever be at the top!
+ _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
#endif
- const _Tp* _M_keyp = &_M_key;
- int _M_source = _M_losers[0]._M_source;
- for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
- {
- // The smaller one gets promoted.
- if (_M_comp(*(_M_losers[__pos]._M_keyp), *_M_keyp))
- {
- // The other one is smaller.
- std::swap(_M_losers[__pos]._M_source, _M_source);
- std::swap(_M_losers[__pos]._M_keyp, _M_keyp);
- }
- }
+ const _Tp* _M_keyp = &_M_key;
+ int _M_source = _M_losers[0]._M_source;
+ for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
+ {
+ // The smaller one gets promoted.
+ if (_M_comp(*(_M_losers[__pos]._M_keyp), *_M_keyp))
+ {
+ // The other one is smaller.
+ std::swap(_M_losers[__pos]._M_source, _M_source);
+ std::swap(_M_losers[__pos]._M_keyp, _M_keyp);
+ }
+ }
- _M_losers[0]._M_source = _M_source;
- _M_losers[0]._M_keyp = _M_keyp;
- }
-};
-
+ _M_losers[0]._M_source = _M_source;
+ _M_losers[0]._M_keyp = _M_keyp;
+ }
+ };
} // namespace __gnu_parallel
#endif /* _GLIBCXX_PARALLEL_LOSERTREE_H */