mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-16 15:14:13 +00:00
add doc: all non-modifying sequence operation
This commit is contained in:
parent
d58e8ce805
commit
c5af780d6b
26 changed files with 2104 additions and 10 deletions
43
source/libs/sprout/algorithm/count.rst
Normal file
43
source/libs/sprout/algorithm/count.rst
Normal file
|
@ -0,0 +1,43 @@
|
|||
.. _sprout-algorithm-count:
|
||||
###############################################################################
|
||||
count
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename InputIterator, typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
||||
count(InputIterator first, InputIterator last, T const& value);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The number of iterators i in the range [first,last) for which the following corresponding conditions hold: ``*i == value``.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/count.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, 5, 5, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::count(begin(input), end(input), 5);
|
||||
static_assert(result == 4, "counted 4 elements equal to 5 from input.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| Exactly ``last - first`` applications of the predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/count.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
44
source/libs/sprout/algorithm/count_if.rst
Normal file
44
source/libs/sprout/algorithm/count_if.rst
Normal file
|
@ -0,0 +1,44 @@
|
|||
.. _sprout-algorithm-count_if:
|
||||
###############################################################################
|
||||
count_if
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename InputIterator, typename Predicate>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::difference_type
|
||||
count_if(InputIterator first, InputIterator last, Predicate pred);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The number of iterators i in the range [first,last) for which the following corresponding conditions hold: ``pred(*i)``.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/count_if.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
#include <sprout/functional.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::count_if(begin(input), end(input), bind2nd(modulus<>(), 2));
|
||||
static_assert(result == 5, "counted 5 elements of odd number from input.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| Exactly ``last - first`` applications of the predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/count_if.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
64
source/libs/sprout/algorithm/equal.rst
Normal file
64
source/libs/sprout/algorithm/equal.rst
Normal file
|
@ -0,0 +1,64 @@
|
|||
.. _sprout-algorithm-equal:
|
||||
###############################################################################
|
||||
equal
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred);
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred);
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| If last2 was not given in the argument list, it denotes ``first2 + (last1 - first1)`` below.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| If ``last1 - first1 != last2 - first2``, return false.
|
||||
| Otherwise return true if for every iterator i in the range [first1,last1) the following corresponding conditions hold: ``*i == *(first2 + (i - first1))``, ``pred(*i, *(first2 + (i - first1)))``.
|
||||
| Otherwise, returns false.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/equal.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, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto input2 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::equal(begin(input1), end(input1), begin(input2), end(input2));
|
||||
static_assert(result, "input2 equals to input1.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| No applications of the corresponding predicate if InputIterator1 and InputIterator2 meet the requirements of random access iterators and ``last1 - first1 != last2 - first2``.
|
||||
| Otherwise, at most ``min(last1 - first1, last2 - first2)`` applications of the corresponding predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/equal.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
|
@ -20,6 +20,13 @@ Sprout.Algorithm
|
|||
find_end
|
||||
find_first_of
|
||||
adjacent_find
|
||||
count
|
||||
count_if
|
||||
mismatch
|
||||
equal
|
||||
is_permutation
|
||||
search
|
||||
search_n
|
||||
|
||||
.. _sprout-algorithm-non_modifying:
|
||||
*******************************************************************************
|
||||
|
@ -44,6 +51,7 @@ Non-modifying sequence operations
|
|||
* :doc:`count_if <./count_if>`
|
||||
* :doc:`mismatch <./mismatch>`
|
||||
* :doc:`equal <./equal>`
|
||||
* :doc:`is_permutation <./is_permutation>`
|
||||
* :doc:`search <./search>`
|
||||
* :doc:`search_n <./search_n>`
|
||||
|
||||
|
@ -98,7 +106,6 @@ Permutation generators
|
|||
|
||||
* :doc:`next_permutation <./next_permutation>`
|
||||
* :doc:`prev_permutation <./prev_permutation>`
|
||||
* :doc:`is_permutation <./is_permutation>`
|
||||
|
||||
.. _sprout-algorithm-non_modifying-clamp:
|
||||
Clamp algorithm
|
||||
|
|
63
source/libs/sprout/algorithm/is_permutation.rst
Normal file
63
source/libs/sprout/algorithm/is_permutation.rst
Normal file
|
@ -0,0 +1,63 @@
|
|||
.. _sprout-algorithm-is_permutation:
|
||||
###############################################################################
|
||||
is_permutation
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred);
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2) {
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| If last2 was not given in the argument list, it denotes ``first2 + (last1 - first1)`` below.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| If ``last1 - first1 != last2 - first2``, return false.
|
||||
| Otherwise return true if there exists a permutation of the elements in the range [first2,first2 + (last1 - first1)), beginning with ForwardIterator2 begin, such that ``equal(first1, last1, begin)`` returns true or ``equal(first1, last1, begin, pred)`` returns true; otherwise, returns false.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/is_permutation.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, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto input2 = array<int, 10>{{10, 9, 8, 1, 2, 3, 4, 5, 6, 7}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_permutation(begin(input1), end(input1), begin(input2), end(input2));
|
||||
static_assert(result, "input2 is a permutation of input1.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| No applications of the corresponding predicate if ForwardIterator1 and ForwardIterator2 meet the requirements of random access iterators and ``last1 - first1 != last2 - first2``.
|
||||
| Otherwise, exactly distance(first1, last1) applications of the corresponding predicate if ``equal(first1, last1, first2, last2)`` would return true if pred was not given in the argument list or ``equal(first1, last1, first2, last2, pred)`` would return true if pred was given in the argument list; otherwise, at worst O(N^2), where N has the value ``distance(first1, last1)``.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/is_permutation.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
66
source/libs/sprout/algorithm/mismatch.rst
Normal file
66
source/libs/sprout/algorithm/mismatch.rst
Normal file
|
@ -0,0 +1,66 @@
|
|||
.. _sprout-algorithm-mismatch:
|
||||
###############################################################################
|
||||
mismatch
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred);
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2;
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<InputIterator1, InputIterator2>
|
||||
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred);
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| If last2 was not given in the argument list, it denotes ``first2 + (last1 - first1)`` below.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| A pair of iterators i and j such that ``j == first2 + (i - first1)`` and i is the first iterator in the range [first1,last1) for which the following corresponding conditions hold:
|
||||
* j is in the range [first2,last2).
|
||||
* ``!(*i == *(first2 + (i - first1)))``
|
||||
* ``!pred(*i, *(first2 + (i - first1)))``
|
||||
| Returns the pair ``first1 + min(last1 - first1, last2 - first2)`` and ``first2 + min(last1 - first1, last2 - first2)`` if such an iterator i is not found.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/mismatch.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, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto input2 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 10, 9, 8}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::mismatch(begin(input1), end(input1), begin(input2), end(input2));
|
||||
static_assert(result.first != end(input1) && result.second != end(input2), "input2 mismatches with input1.");
|
||||
static_assert(result.first - begin(input1) == 7, "a mismatched position is 7.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| At most ``last1 - first1`` applications of the corresponding predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/mismatch.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
62
source/libs/sprout/algorithm/search.rst
Normal file
62
source/libs/sprout/algorithm/search.rst
Normal file
|
@ -0,0 +1,62 @@
|
|||
.. _sprout-algorithm-search:
|
||||
###############################################################################
|
||||
search
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator1
|
||||
search(
|
||||
ForwardIterator1 first1, ForwardIterator1 last1,
|
||||
ForwardIterator2 first2, ForwardIterator2 last2
|
||||
);
|
||||
|
||||
template<typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator1
|
||||
search(
|
||||
ForwardIterator1 first1, ForwardIterator1 last1,
|
||||
ForwardIterator2 first2, ForwardIterator2 last2,
|
||||
BinaryPredicate pred
|
||||
);
|
||||
|
||||
Effects
|
||||
========================================
|
||||
|
||||
| Finds a subsequence of equal values in a sequence.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The first iterator i in the range [first1,last1 - (last2-first2)) such that for any nonnegative integer n less than ``last2 - first2`` the following corresponding conditions hold: ``*(i + n) == *(first2 + n)``, ``pred(*(i + n), *(first2 + n))``.
|
||||
| Returns first1 if [first2,last2) is empty, otherwise returns last1 if no such iterator is found.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/search.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::search(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) == 2, "a found position is 2.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| At most ``(last1 - first1) * (last2 - first2)`` applications of the corresponding predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/search.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
59
source/libs/sprout/algorithm/search_n.rst
Normal file
59
source/libs/sprout/algorithm/search_n.rst
Normal file
|
@ -0,0 +1,59 @@
|
|||
.. _sprout-algorithm-search_n:
|
||||
###############################################################################
|
||||
search_n
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ForwardIterator, typename Size, typename T>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator
|
||||
search_n(ForwardIterator first, ForwardIterator last, Size count, T const& value);
|
||||
|
||||
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);
|
||||
|
||||
Requires
|
||||
========================================
|
||||
|
||||
| The type Size shall be convertible to integral type.
|
||||
|
||||
Effects
|
||||
========================================
|
||||
|
||||
| Finds a subsequence of equal values in a sequence.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The first iterator i in the range [first,last-count) such that for any non-negative integer n less than count the following corresponding conditions hold: ``*(i + n) == value``, ``pred(*(i + n),value)``.
|
||||
| Returns last if no such iterator is found.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/search_n.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input1 = array<int, 10>{{1, 2, 3, 5, 5, 5, 5, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::search_n(begin(input1), end(input1), 4, 5);
|
||||
static_assert(result != end(input1), "found a subsequence equal to 4 values of 5 from input1.");
|
||||
static_assert(result - begin(input1) == 3, "a found position is 3.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| At most ``last - first`` applications of the corresponding predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/search_n.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue