From 5d1a341654041c0ca62625a7f4785aae8224af83 Mon Sep 17 00:00:00 2001 From: Tobias Fuchs Date: Mon, 2 Mar 2015 11:23:42 +0100 Subject: [PATCH] algorithms_cpp: added guard definition for QuickSort, MergeSort restricting to RAI --- algorithms_cpp/include/embb/algorithms/internal/merge_sort-inl.h | 22 ++++++++++++++++------ algorithms_cpp/include/embb/algorithms/internal/quick_sort-inl.h | 23 +++++++++++++++++------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/algorithms_cpp/include/embb/algorithms/internal/merge_sort-inl.h b/algorithms_cpp/include/embb/algorithms/internal/merge_sort-inl.h index 163f4ca..a56d582 100644 --- a/algorithms_cpp/include/embb/algorithms/internal/merge_sort-inl.h +++ b/algorithms_cpp/include/embb/algorithms/internal/merge_sort-inl.h @@ -213,19 +213,18 @@ class MergeSortFunctor { } }; -} // namespace internal - template -void MergeSort( +void MergeSortIteratorCheck( RAI first, RAI last, RAITemp temporary_first, ComparisonFunction comparison, const embb::mtapi::ExecutionPolicy& policy, - size_t block_size + size_t block_size, + std::random_access_iterator_tag ) { typedef typename std::iterator_traits::difference_type difference_type; - typedef internal::MergeSortFunctor + typedef MergeSortFunctor functor_t; difference_type distance = std::distance(first, last); if (distance == 0) { @@ -249,7 +248,7 @@ void MergeSort( "Not enough MTAPI tasks available to perform merge sort"); } - internal::BlockSizePartitioner partitioner(first, last, block_size); + BlockSizePartitioner partitioner(first, last, block_size); functor_t functor(0, partitioner.Size() - 1, temporary_first, @@ -266,6 +265,17 @@ void MergeSort( task.Wait(MTAPI_INFINITE); } +} // namespace internal + +template +void MergeSort(RAI first, RAI last, RAITemp temporary_first, + ComparisonFunction comparison, const embb::mtapi::ExecutionPolicy& policy, + size_t block_size) { + typedef typename std::iterator_traits::iterator_category category; + internal::MergeSortIteratorCheck(first, last, temporary_first, comparison, + policy, block_size, category()); +} + } // namespace algorithms } // namespace embb diff --git a/algorithms_cpp/include/embb/algorithms/internal/quick_sort-inl.h b/algorithms_cpp/include/embb/algorithms/internal/quick_sort-inl.h index 6df4caa..d8fa300 100644 --- a/algorithms_cpp/include/embb/algorithms/internal/quick_sort-inl.h +++ b/algorithms_cpp/include/embb/algorithms/internal/quick_sort-inl.h @@ -186,11 +186,12 @@ class QuickSortFunctor { QuickSortFunctor(const QuickSortFunctor&); }; -} // namespace internal - template -void QuickSort(RAI first, RAI last, ComparisonFunction comparison, - const embb::mtapi::ExecutionPolicy& policy, size_t block_size) { +void QuickSortIteratorCheck(RAI first, RAI last, + ComparisonFunction comparison, + const embb::mtapi::ExecutionPolicy& policy, + size_t block_size, + std::random_access_iterator_tag) { embb::mtapi::Node& node = embb::mtapi::Node::GetInstance(); typedef typename std::iterator_traits::difference_type difference_type; difference_type distance = std::distance(first, last); @@ -212,13 +213,23 @@ void QuickSort(RAI first, RAI last, ComparisonFunction comparison, EMBB_THROW(embb::base::ErrorException, "Not enough MTAPI tasks available for performing quick sort"); } - internal::QuickSortFunctor functor( + QuickSortFunctor functor( first, last, comparison, policy, block_size); mtapi::Task task = node.Spawn(mtapi::Action(base::MakeFunction( - functor, &internal::QuickSortFunctor::Action))); + functor, &QuickSortFunctor::Action))); task.Wait(MTAPI_INFINITE); } +} // namespace internal + +template +void QuickSort(RAI first, RAI last, ComparisonFunction comparison, + const embb::mtapi::ExecutionPolicy& policy, size_t block_size) { + typedef typename std::iterator_traits::iterator_category category; + internal::QuickSortIteratorCheck(first, last, comparison, + policy, block_size, category()); +} + } // namespace algorithms } // namespace embb -- libgit2 0.26.0