diff --git a/sprout/algorithm/bogo_sort.hpp b/sprout/algorithm/bogo_sort.hpp index 905410dc..7526e37a 100644 --- a/sprout/algorithm/bogo_sort.hpp +++ b/sprout/algorithm/bogo_sort.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_BOGO_SORT_HPP diff --git a/sprout/algorithm/bozo_sort.hpp b/sprout/algorithm/bozo_sort.hpp index b138623e..66e2d22c 100644 --- a/sprout/algorithm/bozo_sort.hpp +++ b/sprout/algorithm/bozo_sort.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_BOZO_SORT_HPP diff --git a/sprout/algorithm/clamp_range.hpp b/sprout/algorithm/clamp_range.hpp index 0ed029d5..51850081 100644 --- a/sprout/algorithm/clamp_range.hpp +++ b/sprout/algorithm/clamp_range.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_CLAMP_RANGE_HPP diff --git a/sprout/algorithm/copy_until.hpp b/sprout/algorithm/copy_until.hpp index 3e8414c4..a9d6c9e4 100644 --- a/sprout/algorithm/copy_until.hpp +++ b/sprout/algorithm/copy_until.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_COPY_UNTIL_HPP diff --git a/sprout/algorithm/copy_while.hpp b/sprout/algorithm/copy_while.hpp index 26139f10..3752b269 100644 --- a/sprout/algorithm/copy_while.hpp +++ b/sprout/algorithm/copy_while.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_COPY_WHILE_HPP diff --git a/sprout/algorithm/cxx14/partial_sort.hpp b/sprout/algorithm/cxx14/partial_sort.hpp index 2884a49b..4bce9914 100644 --- a/sprout/algorithm/cxx14/partial_sort.hpp +++ b/sprout/algorithm/cxx14/partial_sort.hpp @@ -8,20 +8,50 @@ #ifndef SPROUT_ALGORITHM_CXX14_PARTIAL_SORT_HPP #define SPROUT_ALGORITHM_CXX14_PARTIAL_SORT_HPP +#include +#include #include +#include +#include +#include +#include +#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT namespace sprout { + namespace detail { + template + inline SPROUT_CXX14_CONSTEXPR void + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp) { + typedef typename std::iterator_traits::difference_type difference_type; + sprout::detail::make_heap(first, middle, comp); + difference_type len = middle - first; + for (RandomAccessIterator i = middle; i != last; ++i) { + if (comp(*i, *first)) { + sprout::swap(*i, *first); + sprout::detail::push_heap_front(first, middle, comp, len); + } + } + sprout::detail::sort_heap(first, middle, comp); + } + } // namespace detail // // 25.4.1.3 partial_sort // - // !!! TODO: implementation - template - inline SPROUT_CXX14_CONSTEXPR void - partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last); - template inline SPROUT_CXX14_CONSTEXPR void - partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp); + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp) { + typedef typename std::add_lvalue_reference::type compare_ref; + sprout::detail::partial_sort(first, middle, last, comp); + } + + template + inline SPROUT_CXX14_CONSTEXPR void + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last) { + sprout::partial_sort( + first, middle, last, + NS_SSCRISK_CEL_OR_SPROUT::less::value_type>() + ); + } } // namespace sprout #endif // #ifndef SPROUT_ALGORITHM_CXX14_PARTIAL_SORT_HPP diff --git a/sprout/algorithm/cxx14/partial_sort_copy.hpp b/sprout/algorithm/cxx14/partial_sort_copy.hpp index 4b7b113b..82b56ba4 100644 --- a/sprout/algorithm/cxx14/partial_sort_copy.hpp +++ b/sprout/algorithm/cxx14/partial_sort_copy.hpp @@ -8,20 +8,56 @@ #ifndef SPROUT_ALGORITHM_CXX14_PARTIAL_SORT_COPY_HPP #define SPROUT_ALGORITHM_CXX14_PARTIAL_SORT_COPY_HPP +#include +#include #include +#include +#include +#include +#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT namespace sprout { + namespace detail { + template + inline SPROUT_CXX14_CONSTEXPR RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp) { + typedef typename std::iterator_traits::difference_type difference_type; + RandomAccessIterator r = result_first; + if (r != result_last) { + difference_type len = 0; + for (; first != last && r != result_last; ++first, ++r, ++len) { + *r = *first; + } + sprout::detail::make_heap(result_first, r, comp); + for (; first != last; ++first) { + if (comp(*first, *result_first)) { + *result_first = *first; + sprout::detail::push_heap_front(result_first, r, comp, len); + } + } + sprout::detail::sort_heap(result_first, r, comp); + } + return r; + } + } // namespace detail // // 25.4.1.4 partial_sort_copy // - // !!! TODO: implementation - template - inline SPROUT_CXX14_CONSTEXPR RandomAccessIterator - partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last); - template inline SPROUT_CXX14_CONSTEXPR RandomAccessIterator - partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp); + partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp) { + typedef typename std::add_lvalue_reference::type compare_ref; + return sprout::detail::partial_sort_copy(first, last, result_first, result_last, comp); + } + + template + inline SPROUT_CXX14_CONSTEXPR RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last) { + return sprout::partial_sort_copy( + first, last, result_first, result_last, + NS_SSCRISK_CEL_OR_SPROUT::less::value_type>() + ); + } } // namespace sprout #endif // #ifndef SPROUT_ALGORITHM_CXX14_PARTIAL_SORT_COPY_HPP diff --git a/sprout/algorithm/inplace_merge.hpp b/sprout/algorithm/inplace_merge.hpp index 00b84893..2bcfc770 100644 --- a/sprout/algorithm/inplace_merge.hpp +++ b/sprout/algorithm/inplace_merge.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_INPLACE_MERGE_HPP diff --git a/sprout/algorithm/make_heap.hpp b/sprout/algorithm/make_heap.hpp index 72c82de0..950281b5 100644 --- a/sprout/algorithm/make_heap.hpp +++ b/sprout/algorithm/make_heap.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_MAKE_HEAP_HPP diff --git a/sprout/algorithm/merge.hpp b/sprout/algorithm/merge.hpp index 892c7585..4a4287c4 100644 --- a/sprout/algorithm/merge.hpp +++ b/sprout/algorithm/merge.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_MERGE_HPP diff --git a/sprout/algorithm/next_permutation.hpp b/sprout/algorithm/next_permutation.hpp index 4919b53a..a8e1728c 100644 --- a/sprout/algorithm/next_permutation.hpp +++ b/sprout/algorithm/next_permutation.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_NEXT_PERMUTATION_HPP diff --git a/sprout/algorithm/pop_heap.hpp b/sprout/algorithm/pop_heap.hpp index 39cec9c8..8e9e09aa 100644 --- a/sprout/algorithm/pop_heap.hpp +++ b/sprout/algorithm/pop_heap.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_POP_HEAP_HPP diff --git a/sprout/algorithm/prev_permutation.hpp b/sprout/algorithm/prev_permutation.hpp index 9f9f6638..00eb0d93 100644 --- a/sprout/algorithm/prev_permutation.hpp +++ b/sprout/algorithm/prev_permutation.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_PREV_PERMUTATION_HPP diff --git a/sprout/algorithm/push_heap.hpp b/sprout/algorithm/push_heap.hpp index 6126fab4..26df1e10 100644 --- a/sprout/algorithm/push_heap.hpp +++ b/sprout/algorithm/push_heap.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_PUSH_HEAP_HPP diff --git a/sprout/algorithm/random_swap.hpp b/sprout/algorithm/random_swap.hpp index 042c2a63..97b0cdb8 100644 --- a/sprout/algorithm/random_swap.hpp +++ b/sprout/algorithm/random_swap.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_RANDOM_SWAP_HPP diff --git a/sprout/algorithm/set_difference.hpp b/sprout/algorithm/set_difference.hpp index 16af5f3b..fb45bd26 100644 --- a/sprout/algorithm/set_difference.hpp +++ b/sprout/algorithm/set_difference.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_SET_DIFFERENCE_HPP diff --git a/sprout/algorithm/set_intersection.hpp b/sprout/algorithm/set_intersection.hpp index e23e7375..bb9764e7 100644 --- a/sprout/algorithm/set_intersection.hpp +++ b/sprout/algorithm/set_intersection.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_SET_INTERSECTION_HPP diff --git a/sprout/algorithm/set_symmetric_difference.hpp b/sprout/algorithm/set_symmetric_difference.hpp index 3b8e415e..d65afd95 100644 --- a/sprout/algorithm/set_symmetric_difference.hpp +++ b/sprout/algorithm/set_symmetric_difference.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP diff --git a/sprout/algorithm/set_union.hpp b/sprout/algorithm/set_union.hpp index e38eafb2..cb89cc96 100644 --- a/sprout/algorithm/set_union.hpp +++ b/sprout/algorithm/set_union.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_SET_UNION_HPP diff --git a/sprout/algorithm/sort_heap.hpp b/sprout/algorithm/sort_heap.hpp index 7bae2e38..117fa40b 100644 --- a/sprout/algorithm/sort_heap.hpp +++ b/sprout/algorithm/sort_heap.hpp @@ -11,5 +11,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_ALGORITHM_SORT_HEAP_HPP