mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-14 15:04:09 +00:00
fix recursion depth: some algorithms
This commit is contained in:
parent
bb59363682
commit
e2b207d3be
34 changed files with 796 additions and 87 deletions
|
@ -1,6 +1,7 @@
|
|||
#ifndef SPROUT_ALGORITHM_SEARCH_N_HPP
|
||||
#define SPROUT_ALGORITHM_SEARCH_N_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/value_iterator.hpp>
|
||||
|
@ -11,17 +12,15 @@ namespace sprout {
|
|||
// 25.2.13 Search
|
||||
//
|
||||
// recursion depth:
|
||||
// [first, last) is RandomAccessIterator -> O(log N)
|
||||
// otherwise -> O(N)
|
||||
// O(log(N1+N2))
|
||||
//
|
||||
template<typename ForwardIterator, typename Size, typename T, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator
|
||||
search_n(ForwardIterator first, ForwardIterator last, Size count, T const& value, BinaryPredicate pred) {
|
||||
typedef sprout::value_iterator<T const&> iterator;
|
||||
typedef typename iterator::difference_type difference_type;
|
||||
return sprout::search(
|
||||
first, last,
|
||||
iterator(value, static_cast<difference_type>(count)), iterator(value, 0),
|
||||
iterator(value, static_cast<typename std::iterator_traits<iterator>::difference_type>(count)), iterator(value, 0),
|
||||
pred
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue