1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

algorithm を next/prev で再実装

This commit is contained in:
bolero-MURAKAMI 2011-10-02 00:19:13 +09:00
parent 6fe7e88509
commit 628d1caa7e
50 changed files with 310 additions and 189 deletions

View file

@ -3,6 +3,7 @@
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
namespace detail {
@ -42,7 +43,7 @@ namespace sprout {
{
return first == last
? 0
: (*first == value ? 1 : 0) + sprout::detail::count(first + 1, last, value)
: (*first == value ? 1 : 0) + sprout::detail::count(sprout::next(first), last, value)
;
}
@ -58,7 +59,7 @@ namespace sprout {
{
return first == last
? 0
: (pred(*first) ? 1 : 0) + sprout::detail::count_if(first + 1, last, pred);
: (pred(*first) ? 1 : 0) + sprout::detail::count_if(sprout::next(first), last, pred);
}
//
@ -73,7 +74,7 @@ namespace sprout {
{
return first1 == last1
? true
: *first1 == *first2 && sprout::detail::equal(first1 + 1, last1, first2 + 1)
: *first1 == *first2 && sprout::detail::equal(sprout::next(first1), last1, sprout::next(first2))
;
}
template<typename Iterator1, typename Iterator2, typename Predicate>
@ -86,7 +87,7 @@ namespace sprout {
{
return first1 == last1
? true
: pred(*first1, *first2) && sprout::detail::equal(first1 + 1, last1, first2 + 1, pred);
: pred(*first1, *first2) && sprout::detail::equal(sprout::next(first1), last1, sprout::next(first2), pred);
}
//
@ -106,7 +107,7 @@ namespace sprout {
? true
: *first2 < *first1
? false
: sprout::detail::lexicographical_compare(first1 + 1, last1, first2 + 1, last2);
: sprout::detail::lexicographical_compare(sprout::next(first1), last1, sprout::next(first2), last2);
}
template<typename Iterator1, typename Iterator2, typename Compare>
SPROUT_CONSTEXPR bool lexicographical_compare(
@ -123,7 +124,7 @@ namespace sprout {
? true
: comp(*first2, *first1)
? false
: sprout::detail::lexicographical_compare(first1 + 1, last1, first2 + 1, last2, comp);
: sprout::detail::lexicographical_compare(sprout::next(first1), last1, sprout::next(first2), last2, comp);
}
} // namespace detail
} // namespace sprout

View file

@ -3,6 +3,7 @@
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
namespace detail {
@ -15,7 +16,7 @@ namespace sprout {
Iterator last
)
{
return first == last ? 0 : 1 + sprout::detail::distance(first + 1, last);
return first == last ? 0 : 1 + sprout::detail::distance(sprout::next(first), last);
}
template<typename Iterator>
@ -30,7 +31,7 @@ namespace sprout {
? current
: first2 == last
? -current
: sprout::detail::bidirectional_distance_impl(first1 + 1, first2 - 1, last, current + 1)
: sprout::detail::bidirectional_distance_impl(sprout::next(first1), sprout::prev(first2), last, current + 1)
;
}
//
@ -42,7 +43,7 @@ namespace sprout {
Iterator last
)
{
return first == last ? 0 : sprout::detail::bidirectional_distance_impl(first + 1, first - 1, last);
return first == last ? 0 : sprout::detail::bidirectional_distance_impl(sprout::next(first), sprout::prev(first), last);
}
} // namespace detail
} // namespace sprout

View file

@ -3,6 +3,7 @@
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
namespace detail {
@ -17,8 +18,8 @@ namespace sprout {
return first == last
? 0
: *first == value
? 1 + sprout::detail::overlap_count_impl(first + 1, last, value)
: sprout::detail::overlap_count_impl(first + 1, last, *first)
? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, value)
: sprout::detail::overlap_count_impl(sprout::next(first), last, *first)
;
}
//
@ -32,7 +33,7 @@ namespace sprout {
{
return first == last
? 0
: sprout::detail::overlap_count_impl(first + 1, last, *first)
: sprout::detail::overlap_count_impl(sprout::next(first), last, *first)
;
}
@ -47,8 +48,8 @@ namespace sprout {
return first == last
? 0
: pred(*first, value)
? 1 + sprout::detail::overlap_count_impl(first + 1, last, pred, value)
: sprout::detail::overlap_count_impl(first + 1, last, pred, *first)
? 1 + sprout::detail::overlap_count_impl(sprout::next(first), last, pred, value)
: sprout::detail::overlap_count_impl(sprout::next(first), last, pred, *first)
;
}
//
@ -63,7 +64,7 @@ namespace sprout {
{
return first == last
? 0
: sprout::detail::overlap_count_impl(first + 1, last, pred, *first)
: sprout::detail::overlap_count_impl(sprout::next(first), last, pred, *first)
;
}
} // namespace detail

View file

@ -3,6 +3,7 @@
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
namespace detail {
@ -20,10 +21,10 @@ namespace sprout {
{
return first1 != last1 && first2 != last2
? comp(*first1, *first2)
? sprout::detail::overlap_count_2(first1 + 1, last1, first2, last2, comp)
? sprout::detail::overlap_count_2(sprout::next(first1), last1, first2, last2, comp)
: comp(*first2, *first1)
? sprout::detail::overlap_count_2(first1, last1, first2 + 1, last2, comp)
: 1 + sprout::detail::overlap_count_2(first1 + 1, last1, first2 + 1, last2, comp)
? sprout::detail::overlap_count_2(first1, last1, sprout::next(first2), last2, comp)
: 1 + sprout::detail::overlap_count_2(sprout::next(first1), last1, sprout::next(first2), last2, comp)
: 0
;
}
@ -40,10 +41,10 @@ namespace sprout {
{
return first1 != last1 && first2 != last2
? *first1 < *first2
? sprout::detail::overlap_count_2(first1 + 1, last1, first2, last2)
? sprout::detail::overlap_count_2(sprout::next(first1), last1, first2, last2)
: *first2 < *first1
? sprout::detail::overlap_count_2(first1, last1, first2 + 1, last2)
: 1 + sprout::detail::overlap_count_2(first1 + 1, last1, first2 + 1, last2)
? sprout::detail::overlap_count_2(first1, last1, sprout::next(first2), last2)
: 1 + sprout::detail::overlap_count_2(sprout::next(first1), last1, sprout::next(first2), last2)
: 0
;
}