mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-12 14:54:10 +00:00
add doc:is_sorted, is_sorted_until
This commit is contained in:
parent
2cfe358464
commit
15397fdd71
13 changed files with 537 additions and 5 deletions
|
@ -27,6 +27,8 @@ Sprout.Algorithm
|
|||
is_permutation
|
||||
search
|
||||
search_n
|
||||
is_sorted
|
||||
is_sorted_until
|
||||
|
||||
.. _sprout-algorithm-non_modifying:
|
||||
*******************************************************************************
|
||||
|
|
46
source/libs/sprout/algorithm/is_sorted.rst
Normal file
46
source/libs/sprout/algorithm/is_sorted.rst
Normal file
|
@ -0,0 +1,46 @@
|
|||
.. _sprout-algorithm-is_sorted:
|
||||
###############################################################################
|
||||
is_sorted
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ForwardIterator>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_sorted(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template<typename ForwardIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| ``is_sorted_until(first, last) == last``, ``is_sorted_until(first, last, comp) == last``
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/is_sorted.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.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::is_sorted(begin(input), end(input));
|
||||
static_assert(result, "input is sorted.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/is_sorted.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
48
source/libs/sprout/algorithm/is_sorted_until.rst
Normal file
48
source/libs/sprout/algorithm/is_sorted_until.rst
Normal file
|
@ -0,0 +1,48 @@
|
|||
.. _sprout-algorithm-is_sorted_until:
|
||||
###############################################################################
|
||||
is_sorted_until
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename ForwardIterator>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator
|
||||
is_sorted_until(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template<typename ForwardIterator, typename Compare>
|
||||
inline SPROUT_CONSTEXPR ForwardIterator
|
||||
is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| If ``distance(first, last) < 2``, returns last.
|
||||
| Otherwise, returns the last iterator i in [first,last] for which the range [first,i) is sorted.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/is_sorted_until.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{6, 7, 8, 8, 10, 1, 2, 3, 4, 5}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::is_sorted_until(begin(input), end(input));
|
||||
static_assert(result - begin(input) == 5, "input is sorted until position 5.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| Linear.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/is_sorted_until.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue