mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
reduce includes' complexity on some inputs
cf. http://melpon.org/wandbox/permlink/mVNO3IDW8aawsRtD
This commit is contained in:
parent
b51e338b68
commit
9b5a965efd
1 changed files with 28 additions and 17 deletions
|
@ -19,24 +19,29 @@
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename RandomAccessIterator1, typename InputIterator2, typename Compare>
|
template<typename RandomAccessIterator1, typename InputIterator2, typename Compare>
|
||||||
inline SPROUT_CONSTEXPR InputIterator2
|
inline SPROUT_CONSTEXPR sprout::pair<InputIterator2, bool>
|
||||||
includes_impl_ra(
|
includes_impl_ra(
|
||||||
RandomAccessIterator1 first1, RandomAccessIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp,
|
RandomAccessIterator1 first1,
|
||||||
typename std::iterator_traits<RandomAccessIterator1>::difference_type pivot
|
sprout::pair<InputIterator2, bool> current,
|
||||||
|
InputIterator2 last2, Compare comp,
|
||||||
|
typename std::iterator_traits<RandomAccessIterator1>::difference_type len
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return first2 == last2 ? first2
|
typedef sprout::pair<InputIterator2, bool> type;
|
||||||
: pivot == 0 ? (!comp(*first1, *first2) && !comp(*first2, *first1) ? sprout::next(first2) : first2)
|
return current.second || current.first == last2 ? current
|
||||||
|
: len == 1 ? comp(*current.first, *first1)
|
||||||
|
? type(current.first, true)
|
||||||
|
: type(comp(*first1, *current.first) ? current.first : sprout::next(current.first), false)
|
||||||
: sprout::detail::includes_impl_ra(
|
: sprout::detail::includes_impl_ra(
|
||||||
sprout::next(first1, pivot), last1,
|
sprout::next(first1, len / 2),
|
||||||
sprout::detail::includes_impl_ra(
|
sprout::detail::includes_impl_ra(
|
||||||
first1, sprout::next(first1, pivot),
|
first1,
|
||||||
first2,
|
current,
|
||||||
last2, comp,
|
last2, comp,
|
||||||
pivot / 2
|
len / 2
|
||||||
),
|
),
|
||||||
last2, comp,
|
last2, comp,
|
||||||
(sprout::distance(first1, last1) - pivot) / 2
|
len - len / 2
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -52,9 +57,11 @@ namespace sprout {
|
||||||
{
|
{
|
||||||
return first1 == last1 ? first2 == last2
|
return first1 == last1 ? first2 == last2
|
||||||
: sprout::detail::includes_impl_ra(
|
: sprout::detail::includes_impl_ra(
|
||||||
first1, last1, first2, last2, comp,
|
first1,
|
||||||
sprout::distance(first1, last1) / 2
|
sprout::pair<InputIterator2, bool>(first2, false),
|
||||||
)
|
last2, comp,
|
||||||
|
sprout::distance(first1, last1)
|
||||||
|
).first
|
||||||
== last2
|
== last2
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -69,15 +76,19 @@ namespace sprout {
|
||||||
{
|
{
|
||||||
typedef sprout::pair<InputIterator1, InputIterator2> type;
|
typedef sprout::pair<InputIterator1, InputIterator2> type;
|
||||||
return current.second == last2 || current.first == last1 ? current
|
return current.second == last2 || current.first == last1 ? current
|
||||||
: n == 1 ? !comp(*current.first, *current.second) && !comp(*current.second, *current.first)
|
: n == 1
|
||||||
? type(sprout::next(current.first), sprout::next(current.second))
|
? comp(*current.second, *current.first)
|
||||||
: type(sprout::next(current.first), current.second)
|
? type(last1, current.second)
|
||||||
|
: type(
|
||||||
|
sprout::next(current.first),
|
||||||
|
comp(*current.first, *current.second) ? current.second : sprout::next(current.second)
|
||||||
|
)
|
||||||
: sprout::detail::includes_impl_1(
|
: sprout::detail::includes_impl_1(
|
||||||
sprout::detail::includes_impl_1(
|
sprout::detail::includes_impl_1(
|
||||||
current,
|
current,
|
||||||
last1, last2, comp, n / 2
|
last1, last2, comp, n / 2
|
||||||
),
|
),
|
||||||
last1, last2, comp, n - n / 2
|
last1, last2, comp, n / 2
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue