RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
RandomAccessIterator3 target,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
_GLIBCXX_CALL(length);
multiway_merge_4_variant(RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
RandomAccessIterator3 target,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
_GLIBCXX_CALL(length);
typedef _DifferenceTp difference_type;
multiway_merge_loser_tree(RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
RandomAccessIterator3 target,
- Comparator comp,
- _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
_GLIBCXX_CALL(length)
const typename std::iterator_traits<typename std::iterator_traits<
RandomAccessIteratorIterator>::value_type::first_type>::value_type&
sentinel,
- Comparator comp,
- _DifferenceTp length)
+ _DifferenceTp length,
+ Comparator comp)
{
_GLIBCXX_CALL(length)
typedef _DifferenceTp difference_type;
const typename std::iterator_traits<typename std::iterator_traits<
RandomAccessIteratorIterator>::value_type::first_type>::value_type&
sentinel,
- Comparator comp,
- _DifferenceTp length)
+ _DifferenceTp length,
+ Comparator comp)
{
_GLIBCXX_CALL(length)
target_end = multiway_merge_loser_tree_unguarded
<UnguardedLoserTree>
- (seqs_begin, seqs_end, target, sentinel, comp, length);
+ (seqs_begin, seqs_end, target, sentinel, length, comp);
#if _GLIBCXX_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(target_end == target + length);
RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
RandomAccessIterator3 target,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
return multiway_merge_3_variant<guarded_iterator>(
- seqs_begin, seqs_end, target, comp, length);
+ seqs_begin, seqs_end, target, length, comp);
}
};
RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
RandomAccessIterator3 target,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
return multiway_merge_3_variant<unguarded_iterator>(
- seqs_begin, seqs_end, target, comp, length);
+ seqs_begin, seqs_end, target, length, comp);
}
};
RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
RandomAccessIterator3 target,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
return multiway_merge_4_variant<guarded_iterator>(
- seqs_begin, seqs_end, target, comp, length);
+ seqs_begin, seqs_end, target, length, comp);
}
};
RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
RandomAccessIterator3 target,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
return multiway_merge_4_variant<unguarded_iterator>(
- seqs_begin, seqs_end, target, comp, length);
+ seqs_begin, seqs_end, target, length, comp);
}
};
const typename std::iterator_traits<typename std::iterator_traits<
RandomAccessIteratorIterator>::value_type::first_type>::value_type&
sentinel,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
typedef typename std::iterator_traits<RandomAccessIteratorIterator>
::value_type::first_type
loser_tree_traits<value_type>::use_pointer
, LoserTreePointerUnguarded<stable, value_type, Comparator>
, LoserTreeUnguarded<stable, value_type, Comparator>
- >::__type>(seqs_begin, seqs_end, target, sentinel, comp, length);
+ >::__type>(seqs_begin, seqs_end, target, sentinel, length, comp);
}
};
const typename std::iterator_traits<typename std::iterator_traits<
RandomAccessIteratorIterator>::value_type::first_type>::value_type&
sentinel,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
typedef typename std::iterator_traits<RandomAccessIteratorIterator>
::value_type::first_type
loser_tree_traits<value_type>::use_pointer
, LoserTreePointer<stable, value_type, Comparator>
, LoserTree<stable, value_type, Comparator>
- >::__type >(seqs_begin, seqs_end, target, comp, length);
+ >::__type >(seqs_begin, seqs_end, target, length, comp);
}
};
const typename std::iterator_traits<typename std::iterator_traits<
RandomAccessIteratorIterator>::value_type::first_type>::value_type&
sentinel,
- Comparator comp, _DifferenceTp length)
+ _DifferenceTp length, Comparator comp)
{
_GLIBCXX_CALL(length)
, RandomAccessIteratorIterator
, RandomAccessIterator3
, _DifferenceTp
- , Comparator>()(seqs_begin, seqs_end, target, comp, length);
+ , Comparator>()(seqs_begin, seqs_end, target, length, comp);
break;
case 4:
return_target = multiway_merge_4_variant_sentinel_switch<
, RandomAccessIteratorIterator
, RandomAccessIterator3
, _DifferenceTp
- , Comparator>()(seqs_begin, seqs_end, target, comp, length);
+ , Comparator>()(seqs_begin, seqs_end, target, length, comp);
break;
default:
return_target = multiway_merge_k_variant_sentinel_switch<
, RandomAccessIteratorIterator
, RandomAccessIterator3
, _DifferenceTp
- , Comparator>()
- (seqs_begin, seqs_end, target, sentinel, comp, length);
+ , Comparator>()(seqs_begin, seqs_end, target, sentinel, length, comp);
break;
}
#if _GLIBCXX_ASSERTIONS
void multiway_merge_sampling_splitting(
RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
- Comparator comp, difference_type length,
- difference_type total_length,
+ difference_type length, difference_type total_length, Comparator comp,
std::vector<std::pair<difference_type, difference_type> > *pieces)
{
typedef typename std::iterator_traits<RandomAccessIteratorIterator>
void multiway_merge_exact_splitting(
RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
- Comparator comp,
- difference_type length,
- difference_type total_length,
+ difference_type length, difference_type total_length, Comparator comp,
std::vector<std::pair<difference_type, difference_type> > *pieces)
{
typedef typename std::iterator_traits<RandomAccessIteratorIterator>
parallel_multiway_merge(RandomAccessIteratorIterator seqs_begin,
RandomAccessIteratorIterator seqs_end,
RandomAccessIterator3 target,
- Comparator comp,
Splitter splitter,
- _DifferenceTp length)
+ _DifferenceTp length,
+ Comparator comp,
+ thread_index_t num_threads)
{
#if _GLIBCXX_ASSERTIONS
_GLIBCXX_PARALLEL_ASSERT(seqs_end - seqs_begin > 1);
std::vector<std::pair<difference_type, difference_type> >* pieces;
- thread_index_t num_threads = static_cast<thread_index_t>
- (std::min<difference_type>(get_max_threads(), total_length));
+ num_threads = static_cast<thread_index_t>
+ (std::min<difference_type>(num_threads, total_length));
# pragma omp parallel num_threads (num_threads)
{
__gnu_parallel::_Settings::get().merge_oversampling *
num_threads;
- splitter(ne_seqs, ne_seqs + k, comp, length, total_length,
- pieces);
+ splitter(ne_seqs, ne_seqs + k, length, total_length,
+ comp, pieces);
} //single
thread_index_t iam = omp_get_thread_num();
if(length > target_position)
sequential_multiway_merge<stable, sentinels>(
chunks, chunks + k, target + target_position,
- *(seqs_begin->second), comp, length - target_position);
+ *(seqs_begin->second), length - target_position, comp);
delete[] chunks;
} // parallel
*
* @return end iterator of output sequence
*/
+// multiway_merge
// public interface
template<
typename RandomAccessIteratorPairIterator
multiway_merge(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length)
-{
- typedef _DifferenceTp difference_type;
- _GLIBCXX_CALL(seqs_end - seqs_begin)
-
- // catch special case: no sequences
- if (seqs_begin == seqs_end)
- return target;
-
- // Execute merge; maybe parallel, depending on the number of merged
- // elements and the number of sequences and global thresholds in
- // Settings.
- if ((seqs_end - seqs_begin > 1) &&
- _GLIBCXX_PARALLEL_CONDITION(
- ((seqs_end - seqs_begin) >=
- __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
- && ((sequence_index_t)length >=
- __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
- return parallel_multiway_merge
- </* stable = */ false, /* sentinels = */ false>
- (seqs_begin, seqs_end, target, comp,
- multiway_merge_sampling_splitting</* stable = */ false,
- typename std::iterator_traits<RandomAccessIteratorPairIterator>
- ::value_type*, Comparator, _DifferenceTp>,
- static_cast<difference_type>(length));
- else
- return sequential_multiway_merge
- </* stable = */false, /* sentinels = */ false>(
- seqs_begin, seqs_end,
- target, *(seqs_begin->second), comp, length);
-}
-
-// public interface
-template<
- typename RandomAccessIteratorPairIterator
- , typename RandomAccessIteratorOut
- , typename _DifferenceTp
- , typename Comparator>
-RandomAccessIteratorOut
-multiway_merge(RandomAccessIteratorPairIterator seqs_begin
- , RandomAccessIteratorPairIterator seqs_end
- , RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length
+ , _DifferenceTp length, Comparator comp
, __gnu_parallel::sequential_tag)
{
typedef _DifferenceTp difference_type;
// Execute multiway merge *sequentially*.
return sequential_multiway_merge
</* stable = */ false, /* sentinels = */ false>
- (seqs_begin, seqs_end, target, *(seqs_begin->second), comp, length);
+ (seqs_begin, seqs_end, target, *(seqs_begin->second), length, comp);
}
-//public interface
+// public interface
template<
typename RandomAccessIteratorPairIterator
, typename RandomAccessIteratorOut
multiway_merge(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length
- , __gnu_parallel::exact_tag)
+ , _DifferenceTp length, Comparator comp
+ , __gnu_parallel::exact_tag tag)
{
typedef _DifferenceTp difference_type;
_GLIBCXX_CALL(seqs_end - seqs_begin)
__gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
return parallel_multiway_merge
</* stable = */ false, /* sentinels = */ false>(
- seqs_begin, seqs_end,
- target, comp,
+ seqs_begin, seqs_end, target,
multiway_merge_exact_splitting</* stable = */ false,
typename std::iterator_traits<RandomAccessIteratorPairIterator>
::value_type*, Comparator, _DifferenceTp>,
- static_cast<difference_type>(length));
+ static_cast<difference_type>(length), comp, tag.get_num_threads());
else
return sequential_multiway_merge
</* stable = */ false, /* sentinels = */ false>(
- seqs_begin, seqs_end,
- target, *(seqs_begin->second), comp, length);
+ seqs_begin, seqs_end, target, *(seqs_begin->second), length, comp);
}
// public interface
, typename _DifferenceTp
, typename Comparator>
RandomAccessIteratorOut
-stable_multiway_merge(RandomAccessIteratorPairIterator seqs_begin
+multiway_merge(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length)
+ , _DifferenceTp length, Comparator comp
+ , __gnu_parallel::sampling_tag tag)
{
typedef _DifferenceTp difference_type;
_GLIBCXX_CALL(seqs_end - seqs_begin)
if ((seqs_end - seqs_begin > 1) &&
_GLIBCXX_PARALLEL_CONDITION(
((seqs_end - seqs_begin) >=
- __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
+ __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
&& ((sequence_index_t)length >=
__gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
return parallel_multiway_merge
- </* stable = */ true, /* sentinels = */ false>(
+ </* stable = */ false, /* sentinels = */ false>(
seqs_begin, seqs_end,
- target, comp,
- multiway_merge_sampling_splitting</* stable = */ true,
+ target,
+ multiway_merge_exact_splitting</* stable = */ false,
typename std::iterator_traits<RandomAccessIteratorPairIterator>
::value_type*, Comparator, _DifferenceTp>,
- static_cast<difference_type>(length));
+ static_cast<difference_type>(length), comp, tag.get_num_threads());
else
return sequential_multiway_merge
- </* stable = */ true, /* sentinels = */ false>(
+ </* stable = */ false, /* sentinels = */ false>(
seqs_begin, seqs_end,
- target, *(seqs_begin->second), comp, length);
+ target, *(seqs_begin->second), length, comp);
}
+// public interface
+template<
+ typename RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+multiway_merge(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator 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 RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+multiway_merge(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator 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 RandomAccessIteratorPairIterator
stable_multiway_merge(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length
+ , _DifferenceTp length, Comparator comp
, __gnu_parallel::sequential_tag)
{
typedef _DifferenceTp difference_type;
// Execute multiway merge *sequentially*.
return sequential_multiway_merge
</* stable = */ true, /* sentinels = */ false>
- (seqs_begin, seqs_end, target, *(seqs_begin->second), comp, length);
+ (seqs_begin, seqs_end, target, *(seqs_begin->second), length, comp);
}
// public interface
stable_multiway_merge(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length
- , __gnu_parallel::exact_tag)
+ , _DifferenceTp length, Comparator comp
+ , __gnu_parallel::exact_tag tag)
{
typedef _DifferenceTp difference_type;
_GLIBCXX_CALL(seqs_end - seqs_begin)
return parallel_multiway_merge
</* stable = */ true, /* sentinels = */ false>(
seqs_begin, seqs_end,
- target, comp,
- multiway_merge_exact_splitting
- </* stable = */ true,
- typename std::iterator_traits<RandomAccessIteratorPairIterator>
- ::value_type*, Comparator, _DifferenceTp>,
- static_cast<difference_type>(length));
+ target,
+ multiway_merge_exact_splitting</* stable = */ true,
+ typename std::iterator_traits<RandomAccessIteratorPairIterator>
+ ::value_type*, Comparator, _DifferenceTp>,
+ static_cast<difference_type>(length), comp, tag.get_num_threads());
else
return sequential_multiway_merge</* stable = */ true,
/* sentinels = */ false>(
seqs_begin, seqs_end,
- target, *(seqs_begin->second), comp, length);
+ target, *(seqs_begin->second), length, comp);
+}
+
+// public interface
+template<
+ typename RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+stable_multiway_merge(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator comp
+ , sampling_tag tag)
+{
+ typedef _DifferenceTp difference_type;
+ _GLIBCXX_CALL(seqs_end - seqs_begin)
+
+ // catch special case: no sequences
+ if (seqs_begin == seqs_end)
+ return target;
+
+ // Execute merge; maybe parallel, depending on the number of merged
+ // elements and the number of sequences and global thresholds in
+ // Settings.
+ if ((seqs_end - seqs_begin > 1) &&
+ _GLIBCXX_PARALLEL_CONDITION(
+ ((seqs_end - seqs_begin) >=
+ __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
+ && ((sequence_index_t)length >=
+ __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
+ return parallel_multiway_merge
+ </* stable = */ true, /* sentinels = */ false>(
+ seqs_begin, seqs_end,
+ target,
+ multiway_merge_sampling_splitting</* stable = */ true,
+ typename std::iterator_traits<RandomAccessIteratorPairIterator>
+ ::value_type*, Comparator, _DifferenceTp>,
+ static_cast<difference_type>(length), comp, tag.get_num_threads());
+ else
+ return sequential_multiway_merge
+ </* stable = */ true, /* sentinels = */ false>(
+ seqs_begin, seqs_end,
+ target, *(seqs_begin->second), length, comp);
+}
+
+
+// public interface
+template<
+ typename RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+stable_multiway_merge(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator 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 RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+stable_multiway_merge(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator comp
+ , default_parallel_tag tag)
+{
+ return stable_multiway_merge(seqs_begin, seqs_end, target, length, comp,
+ exact_tag(tag.get_num_threads()));
}
/**
*
* @return end iterator of output sequence
*/
+// multiway_merge_sentinels
// public interface
template<
typename RandomAccessIteratorPairIterator
multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length)
-{
- typedef _DifferenceTp difference_type;
- _GLIBCXX_CALL(seqs_end - seqs_begin)
-
- // catch special case: no sequences
- if (seqs_begin == seqs_end)
- return target;
-
- // Execute merge; maybe parallel, depending on the number of merged
- // elements and the number of sequences and global thresholds in
- // Settings.
- if ((seqs_end - seqs_begin > 1) &&
- _GLIBCXX_PARALLEL_CONDITION(
- ((seqs_end - seqs_begin) >=
- __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
- && ((sequence_index_t)length >=
- __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
- return parallel_multiway_merge
- </* stable = */ false, /* sentinels = */ true>
- (seqs_begin, seqs_end, target, comp,
- multiway_merge_sampling_splitting
- </* stable = */ false,
- typename std::iterator_traits<RandomAccessIteratorPairIterator>
- ::value_type*, Comparator, _DifferenceTp>,
- static_cast<difference_type>(length));
- else
- return sequential_multiway_merge
- </* stable = */false, /* sentinels = */ true>(
- seqs_begin, seqs_end,
- target, *(seqs_begin->second), comp, length);
-}
-
-//public interface
-template<
- typename RandomAccessIteratorPairIterator
- , typename RandomAccessIteratorOut
- , typename _DifferenceTp
- , typename Comparator>
-RandomAccessIteratorOut
-multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
- , RandomAccessIteratorPairIterator seqs_end
- , RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length
+ , _DifferenceTp length, Comparator comp
, __gnu_parallel::sequential_tag)
{
typedef _DifferenceTp difference_type;
// Execute multiway merge *sequentially*.
return sequential_multiway_merge
</* stable = */ false, /* sentinels = */ true>
- (seqs_begin, seqs_end, target, *(seqs_begin->second), comp, length);
+ (seqs_begin, seqs_end,
+ target, *(seqs_begin->second), length, comp);
}
// public interface
multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length
- , __gnu_parallel::exact_tag)
+ , _DifferenceTp length, Comparator comp
+ , __gnu_parallel::exact_tag tag)
{
typedef _DifferenceTp difference_type;
_GLIBCXX_CALL(seqs_end - seqs_begin)
return parallel_multiway_merge
</* stable = */ false, /* sentinels = */ true>(
seqs_begin, seqs_end,
- target, comp,
- multiway_merge_exact_splitting
- </* stable = */ false,
- typename std::iterator_traits<RandomAccessIteratorPairIterator>
- ::value_type*, Comparator, _DifferenceTp>,
- static_cast<difference_type>(length));
+ target,
+ multiway_merge_exact_splitting</* stable = */ false,
+ typename std::iterator_traits<RandomAccessIteratorPairIterator>
+ ::value_type*, Comparator, _DifferenceTp>,
+ static_cast<difference_type>(length), comp, tag.get_num_threads());
else
return sequential_multiway_merge
</* stable = */ false, /* sentinels = */ true>(
seqs_begin, seqs_end,
- target, *(seqs_begin->second), comp, length);
+ target, *(seqs_begin->second), length, comp);
}
// public interface
, typename _DifferenceTp
, typename Comparator>
RandomAccessIteratorOut
-stable_multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
+multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length)
+ , _DifferenceTp length, Comparator comp
+ , sampling_tag tag)
{
typedef _DifferenceTp difference_type;
_GLIBCXX_CALL(seqs_end - seqs_begin)
&& ((sequence_index_t)length >=
__gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
return parallel_multiway_merge
- </* stable = */ true, /* sentinels = */ true>(
- seqs_begin, seqs_end,
- target, comp,
- multiway_merge_sampling_splitting
- </* stable = */ true,
- typename std::iterator_traits<RandomAccessIteratorPairIterator>
- ::value_type*, Comparator, _DifferenceTp>,
- static_cast<difference_type>(length));
+ </* stable = */ false, /* sentinels = */ true>
+ (seqs_begin, seqs_end, target,
+ multiway_merge_sampling_splitting</* stable = */ false,
+ typename std::iterator_traits<RandomAccessIteratorPairIterator>
+ ::value_type*, Comparator, _DifferenceTp>,
+ static_cast<difference_type>(length), comp, tag.get_num_threads());
else
return sequential_multiway_merge
- </* stable = */ true, /* sentinels = */ true>(
+ </* stable = */false, /* sentinels = */ true>(
seqs_begin, seqs_end,
- target, *(seqs_begin->second), comp, length);
+ target, *(seqs_begin->second), length, comp);
+}
+
+// public interface
+template<
+ typename RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator 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 RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator 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 RandomAccessIteratorPairIterator
stable_multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length
+ , _DifferenceTp length, Comparator comp
, __gnu_parallel::sequential_tag)
{
typedef _DifferenceTp difference_type;
// Execute multiway merge *sequentially*.
return sequential_multiway_merge
</* stable = */ true, /* sentinels = */ true>
- (seqs_begin, seqs_end, target, *(seqs_begin->second), comp, length);
+ (seqs_begin, seqs_end, target, *(seqs_begin->second), length, comp);
}
// public interface
stable_multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
, RandomAccessIteratorPairIterator seqs_end
, RandomAccessIteratorOut target
- , Comparator comp, _DifferenceTp length
- , __gnu_parallel::exact_tag)
+ , _DifferenceTp length, Comparator comp
+ , __gnu_parallel::exact_tag tag)
{
typedef _DifferenceTp difference_type;
_GLIBCXX_CALL(seqs_end - seqs_begin)
return parallel_multiway_merge
</* stable = */ true, /* sentinels = */ true>(
seqs_begin, seqs_end,
- target, comp,
- multiway_merge_exact_splitting
- </* stable = */ true,
- typename std::iterator_traits<RandomAccessIteratorPairIterator>
- ::value_type*, Comparator, _DifferenceTp>,
- static_cast<difference_type>(length));
+ target,
+ multiway_merge_exact_splitting</* stable = */ true,
+ typename std::iterator_traits<RandomAccessIteratorPairIterator>
+ ::value_type*, Comparator, _DifferenceTp>,
+ static_cast<difference_type>(length), comp, tag.get_num_threads());
else
return sequential_multiway_merge
+ </* stable = */ true, /* sentinels = */ true>(
+ seqs_begin, seqs_end, target, *(seqs_begin->second), length, comp);
+}
+
+// public interface
+template<
+ typename RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+stable_multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator comp
+ , sampling_tag tag)
+{
+ typedef _DifferenceTp difference_type;
+ _GLIBCXX_CALL(seqs_end - seqs_begin)
+
+ // catch special case: no sequences
+ if (seqs_begin == seqs_end)
+ return target;
+
+ // Execute merge; maybe parallel, depending on the number of merged
+ // elements and the number of sequences and global thresholds in
+ // Settings.
+ if ((seqs_end - seqs_begin > 1) &&
+ _GLIBCXX_PARALLEL_CONDITION(
+ ((seqs_end - seqs_begin) >=
+ __gnu_parallel::_Settings::get().multiway_merge_minimal_k)
+ && ((sequence_index_t)length >=
+ __gnu_parallel::_Settings::get().multiway_merge_minimal_n)))
+ return parallel_multiway_merge
</* stable = */ true, /* sentinels = */ true>(
seqs_begin, seqs_end,
- target, *(seqs_begin->second), comp, length);
+ target,
+ multiway_merge_sampling_splitting</* stable = */ true,
+ typename std::iterator_traits<RandomAccessIteratorPairIterator>
+ ::value_type*, Comparator, _DifferenceTp>,
+ static_cast<difference_type>(length), comp, tag.get_num_threads());
+ else
+ return sequential_multiway_merge
+ </* stable = */ true, /* sentinels = */ true>(
+ seqs_begin, seqs_end,
+ target, *(seqs_begin->second), length, comp);
+}
+
+// public interface
+template<
+ typename RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+stable_multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator 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 RandomAccessIteratorPairIterator
+ , typename RandomAccessIteratorOut
+ , typename _DifferenceTp
+ , typename Comparator>
+RandomAccessIteratorOut
+stable_multiway_merge_sentinels(RandomAccessIteratorPairIterator seqs_begin
+ , RandomAccessIteratorPairIterator seqs_end
+ , RandomAccessIteratorOut target
+ , _DifferenceTp length, Comparator 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