From ef5cccee73699ed2e692c39a5ee44175dd1943b0 Mon Sep 17 00:00:00 2001 From: rexy712 Date: Thu, 7 May 2020 11:57:06 -0700 Subject: [PATCH] move quicksort partitioner to detail namespace --- include/rexy/cx/algorithm.hpp | 40 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/include/rexy/cx/algorithm.hpp b/include/rexy/cx/algorithm.hpp index 41e948b..89bf4a6 100644 --- a/include/rexy/cx/algorithm.hpp +++ b/include/rexy/cx/algorithm.hpp @@ -25,34 +25,36 @@ namespace rexy::cx{ - template - constexpr Iter qs_partition(Iter left, Iter right, const Compare& cmp) - noexcept(std::is_nothrow_invocable::value && - noexcept(cx::swap(*left,*right))) - { - auto range = right - left; - auto pivot = left + (range / 2); - auto value = *pivot; + namespace detail{ + template + constexpr Iter qs_partition(Iter left, Iter right, const Compare& cmp) + noexcept(std::is_nothrow_invocable::value && + noexcept(cx::swap(*left,*right))) + { + auto range = right - left; + auto pivot = left + (range / 2); + auto value = *pivot; - //move pivot value all the way to the right side to preserve it - cx::swap(*pivot, *right); - for(auto it = left;it != right;++it){ - if(cmp(*it, value)){ - cx::swap(*left, *it); - ++left; + //move pivot value all the way to the right side to preserve it + cx::swap(*pivot, *right); + for(auto it = left;it != right;++it){ + if(cmp(*it, value)){ + cx::swap(*left, *it); + ++left; + } } + //move pivot value back to proper position + cx::swap(*left, *right); + return left; } - //move pivot value back to proper position - cx::swap(*left, *right); - return left; } template constexpr void quicksort(Iter left, Iter right, const Compare& cmp) - noexcept(noexcept(cx::qs_partition(left, right, cmp))) + noexcept(noexcept(cx::detail::qs_partition(left, right, cmp))) { while(left < right){ auto real_right = right-1; - auto pivot = qs_partition(left, real_right, cmp); + auto pivot = detail::qs_partition(left, real_right, cmp); quicksort(left, pivot, cmp); left = ++pivot; }