mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-04 14:14:09 +00:00
add doc: find_end, find_first_of, adjacent_find
This commit is contained in:
parent
6f3e65071e
commit
d58e8ce805
22 changed files with 911 additions and 13 deletions
49
source/libs/sprout/algorithm/adjacent_find.rst
Normal file
49
source/libs/sprout/algorithm/adjacent_find.rst
Normal file
|
@ -0,0 +1,49 @@
|
|||
.. _sprout-algorithm-adjacent_find:
|
||||
###############################################################################
|
||||
adjacent_find
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ForwardIterator, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator
|
||||
adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
|
||||
|
||||
template<typename ForwardIterator>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator
|
||||
adjacent_find(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The first iterator i such that both i and i + 1 are in the range [first,last) for which the following corresponding conditions hold: ``*i == *(i + 1)``, ``pred(*i, *(i + 1))``.
|
||||
| Returns last if no such iterator is found.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/adjacent_find.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{1, 2, 3, 5, 5, 6, 6, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::adjacent_find(begin(input), end(input));
|
||||
static_assert(result != end(input), "found adjacent elements equal to each other from input.");
|
||||
static_assert(result - begin(input) == 3, "a found position is 3.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| For a nonempty range, exactly ``min((i - first) + 1, (last - first) - 1)`` applications of the corresponding predicate, where i is adjacent_find<6E>fs return value.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/adjacent_find.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
|
@ -29,7 +29,7 @@ Examples
|
|||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::find(begin(input), end(input), 8);
|
||||
static_assert(result != end(input), "found a element equal to 8 from input.");
|
||||
static_assert(*result == 8, "a found iterator is pointing to 8.");
|
||||
static_assert(result - begin(input1) == 7, "a found position is 7.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
|
62
source/libs/sprout/algorithm/find_end.rst
Normal file
62
source/libs/sprout/algorithm/find_end.rst
Normal file
|
@ -0,0 +1,62 @@
|
|||
.. _sprout-algorithm-find:
|
||||
###############################################################################
|
||||
find_end
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator1
|
||||
find_end(
|
||||
ForwardIterator1 first1, ForwardIterator1 last1,
|
||||
ForwardIterator2 first2, ForwardIterator2 last2
|
||||
);
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator1
|
||||
find_end(
|
||||
ForwardIterator1 first1, ForwardIterator1 last1,
|
||||
ForwardIterator2 first2, ForwardIterator2 last2,
|
||||
BinaryPredicate pred
|
||||
);
|
||||
|
||||
Effects
|
||||
========================================
|
||||
|
||||
| Finds a subsequence of equal values in a sequence.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The last iterator i in the range [first1,last1 - (last2 - first2)) such that for any nonnegative integer ``n < (last2 - first2)``, the following corresponding conditions hold: ``*(i + n) == *(first2 + n)``, ``pred(*(i + n), *(first2 + n))``.
|
||||
| Returns last1 if [first2,last2) is empty or if no such iterator is found.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/find_end.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input1 = array<int, 10>{{1, 2, 3, 4, 5, 1, 2, 3, 4, 5}};
|
||||
SPROUT_STATIC_CONSTEXPR auto input2 = array<int, 3>{{3, 4, 5}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::find_end(begin(input1), end(input1), begin(input2), end(input2));
|
||||
static_assert(result != end(input1), "found a subsequence equal to input2 from input1.");
|
||||
static_assert(result - begin(input1) == 7, "a found position is 7.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| At most ``(last2 - first2) * (last1 - first1 - (last2 - first2) + 1)`` applications of the corresponding predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/find_end.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
62
source/libs/sprout/algorithm/find_first_of.rst
Normal file
62
source/libs/sprout/algorithm/find_first_of.rst
Normal file
|
@ -0,0 +1,62 @@
|
|||
.. _sprout-algorithm-find:
|
||||
###############################################################################
|
||||
find_first_of
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename InputIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CONSTEXPR InputIterator1
|
||||
find_first_of(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
ForwardIterator2 first2, ForwardIterator2 last2
|
||||
);
|
||||
|
||||
template<typename InputIterator1, typename ForwardIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR InputIterator1
|
||||
find_first_of(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
ForwardIterator2 first2, ForwardIterator2 last2,
|
||||
BinaryPredicate pred
|
||||
);
|
||||
|
||||
Effects
|
||||
========================================
|
||||
|
||||
| Finds an element that matches one of a set of values.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The first iterator i in the range [first1,last1) such that for some iterator j in the range [first2,last2) the following conditions hold: ``*i == *j``, ``pred(*i,*j)``.
|
||||
| Returns last1 if [first2,last2) is empty or if no such iterator is found.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/find_first_of.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input1 = array<int, 10>{{1, 2, 3, 4, 5, 1, 2, 3, 4, 5}};
|
||||
SPROUT_STATIC_CONSTEXPR auto input2 = array<int, 3>{{3, 4, 5}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::find_first_of(begin(input1), end(input1), begin(input2), end(input2));
|
||||
static_assert(result != end(input1), "found an element equal to an one of input2 from input1.");
|
||||
static_assert(result - begin(input1) == 2, "a found position is 2.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| At most ``(last2 - first2) * (last1 - first1 - (last2 - first2) + 1)`` applications of the corresponding predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/find_first_of.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
|
@ -30,7 +30,7 @@ Examples
|
|||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::find_if(begin(input), end(input), bind2nd(greater<>(), 7));
|
||||
static_assert(result != end(input), "found a element greater than 7 from input.");
|
||||
static_assert(*result == 8, "a found iterator is pointing to 8.");
|
||||
static_assert(result - begin(input1) == 7, "a found position is 7.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
|
|
@ -30,7 +30,7 @@ Examples
|
|||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::find_if_not(begin(input), end(input), bind2nd(less<>(), 8));
|
||||
static_assert(result != end(input), "found a element not less than 8 from input.");
|
||||
static_assert(*result == 8, "a found iterator is pointing to 8.");
|
||||
static_assert(result - begin(input1) == 7, "a found position is 7.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
|
|
@ -17,6 +17,9 @@ Sprout.Algorithm
|
|||
find
|
||||
find_if
|
||||
find_if_not
|
||||
find_end
|
||||
find_first_of
|
||||
adjacent_find
|
||||
|
||||
.. _sprout-algorithm-non_modifying:
|
||||
*******************************************************************************
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue