1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-02-04 21:33:56 +00:00

add doc: Binary search algorithms

This commit is contained in:
Bolero-MURAKAMI 2013-08-23 00:08:35 +09:00
parent 958e2cb7a4
commit c4e3ce3d5e
21 changed files with 1204 additions and 78 deletions

View file

@ -13,30 +13,30 @@ Sprout C++ Libraries
Welcome to the Sprout C++ Libraries
*******************************************************************************
C++11 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others.
| C++11 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others.
.. _sprout-documentation:
*******************************************************************************
Library Documentation
*******************************************************************************
The starting point for the documentation of individual libraries is the :doc:`Libraries page <./libraries>`, which gives a brief description of each library and links to its documentation.
| The starting point for the documentation of individual libraries is the :doc:`Libraries page <./libraries>`, which gives a brief description of each library and links to its documentation.
.. _sprout-project:
*******************************************************************************
Project page
*******************************************************************************
Github: https://github.com/bolero-MURAKAMI/Sprout
* `Project page <http://bolero-murakami.github.io/Sprout/>`_
* `Repository (Github) <https://github.com/bolero-MURAKAMI/Sprout/>`_
.. _sprout-install:
*******************************************************************************
Install
*******************************************************************************
Through the path to the directory. ``/path/to/sprout``
This library can be used in the header only.
| Through the path to the directory. ``/path/to/sprout``
| This library can be used in the header only.
.. _sprout-compilers:
*******************************************************************************
@ -46,7 +46,6 @@ Supported Compilers
Linux:
* GCC, C++11 mode: 4.7.0, 4.7.1, 4.7.2, 4.7.3, 4.8.0, 4.8.1
* Clang, C++11 mode: 3.2, 3.3
.. _sprout-author:
@ -54,30 +53,15 @@ Linux:
Author
*******************************************************************************
Bolero MURAKAMI
* Website: http://www.boleros.x0.com/
* Twitter: https://twitter.com/bolero_murakami
* Facebook: http://www.facebook.com/genya.murakami
* Blog: http://d.hatena.ne.jp/boleros/
* Github: https://github.com/bolero-MURAKAMI
* SlideShare: http://www.slideshare.net/GenyaMurakami
* Mail: contact-lib@boleros.x0.com
| Bolero MURAKAMI `(Mail) <contact-lib@boleros.x0.com>`_
| `[Website] <http://bolero-murakami.github.io/>`_ `[Twitter] <https://twitter.com/bolero_murakami>`_ `[Facebook] <http://www.facebook.com/genya.murakami>`_ `[Blog] <http://d.hatena.ne.jp/boleros/>`_ `[Github] <https://github.com/bolero-MURAKAMI>`_ `[SlideShare] <http://www.slideshare.net/GenyaMurakami>`_
.. _sprout-copyrights:
*******************************************************************************
Copyrights
*******************************************************************************
Copyright (C) 2011-2013 Bolero MURAKAMI.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
| Copyright (C) 2011-2013 Bolero MURAKAMI.
| Distributed under the Boost Software License, Version 1.0.
| (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View file

@ -0,0 +1,53 @@
.. _sprout-algorithm-binary_search:
###############################################################################
binary_search
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<typename ForwardIterator, typename T>
inline SPROUT_CONSTEXPR bool
binary_search(ForwardIterator first, ForwardIterator last, T const& value);
template<typename ForwardIterator, typename T, typename Compare>
inline SPROUT_CONSTEXPR bool
binary_search(ForwardIterator first, ForwardIterator last, T const& value, Compare comp);
Requires
========================================
| The elements e of [first,last) are partitioned with respect to the expressions ``e < value`` and ``!(value < e)`` or ``comp(e, value)`` and ``!comp(value, e)``.
| Also, for all elements e of [first,last), ``e < value`` implies ``!(value < e)`` or ``comp(e, value)`` implies ``!comp(value, e)``.
Returns
========================================
| true if there is an iterator i in the range [first,last) that satisfies the corresponding conditions: ``!(*i < value) && !(value < *i)`` or ``comp(*i, value) && comp(value, *i)``.
Examples
========================================
.. sourcecode:: c++
#include <sprout/algorithm/binary_search.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::binary_search(begin(input), end(input), 5);
static_assert(result, "found 5 by binary search.");
Complexity
========================================
| At most ``log2(last - first) + O(1)`` comparisons.
| Recursive function invocations in *O(logN)* (logarithmic) depth.
Header
========================================
| ``sprout/algorithm/binary_search.hpp``
| Convenience header: ``sprout/algorithm.hpp``

View file

@ -0,0 +1,58 @@
.. _sprout-algorithm-equal_range:
###############################################################################
equal_range
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<typename ForwardIterator, typename T>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
equal_range(ForwardIterator first, ForwardIterator last, T const& value);
template<typename ForwardIterator, typename T, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
equal_range(ForwardIterator first, ForwardIterator last, T const& value, Compare comp);
Requires
========================================
| The elements e of [first,last) shall be partitioned with respect to the expressions ``e < value`` and ``!(value < e)`` or ``comp(e, value)`` and ``!comp(value, e)``.
| Also, for all elements e of [first, last), ``e < value`` shall imply ``!(value < e)`` or ``comp(e, value)`` shall imply ``!comp(value, e)``.
Returns
========================================
| ``make_pair(lower_bound(first, last, value), upper_bound(first, last, value))``
| or
| ``make_pair(lower_bound(first, last, value, comp), upper_bound(first, last, value, comp))``
Examples
========================================
.. sourcecode:: c++
#include <sprout/algorithm/equal_range.hpp>
#include <sprout/algorithm/all_of_equal.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::equal_range(begin(input), end(input), 5);
static_assert(result.first - begin(input) == 3, "a lower bound position is 3.");
static_assert(result.second - begin(input) == 7, "a upper bound position is 7.");
static_assert(sprout::all_of_equal(result.first, result.second. 5), "all of result range is equal to 5.");
Complexity
========================================
| At most ``2 * log2(last - first) + O(1)`` comparisons.
| Recursive function invocations in *O(logN)* (logarithmic) depth.
Header
========================================
| ``sprout/algorithm/equal_range.hpp``
| Convenience header: ``sprout/algorithm.hpp``

View file

@ -33,6 +33,10 @@ Sprout.Algorithm
is_decreasing
is_strictly_increasing
is_strictly_decreasing
lower_bound
upper_bound
equal_range
binary_search
.. _sprout-algorithm-non_modifying:
*******************************************************************************

View file

@ -0,0 +1,52 @@
.. _sprout-algorithm-lower_bound:
###############################################################################
lower_bound
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<typename ForwardIterator, typename T>
inline SPROUT_CONSTEXPR ForwardIterator
lower_bound(ForwardIterator first, ForwardIterator last, T const& value);
template<typename ForwardIterator, typename T, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator
lower_bound(ForwardIterator first, ForwardIterator last, T const& value, Compare comp);
Requires
========================================
| The elements e of [first,last) shall be partitioned with respect to the expression ``e < value`` or ``comp(e, value)``.
Returns
========================================
| The furthermost iterator i in the range [first,last] such that for any iterator j in the range [first,i) the following corresponding conditions hold: ``*j < value`` or ``comp(*j, value)``.
Examples
========================================
.. sourcecode:: c++
#include <sprout/algorithm/lower_bound.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::lower_bound(begin(input), end(input), 5);
static_assert(result - begin(input) == 3, "a lower bound position is 3.");
Complexity
========================================
| At most ``log2(last - first) + O(1)`` comparisons.
| Recursive function invocations in *O(logN)* (logarithmic) depth.
Header
========================================
| ``sprout/algorithm/lower_bound.hpp``
| Convenience header: ``sprout/algorithm.hpp``

View file

@ -0,0 +1,52 @@
.. _sprout-algorithm-upper_bound:
###############################################################################
upper_bound
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<typename ForwardIterator, typename T>
inline SPROUT_CONSTEXPR ForwardIterator
upper_bound(ForwardIterator first, ForwardIterator last, T const& value);
template<typename ForwardIterator, typename T, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator
upper_bound(ForwardIterator first, ForwardIterator last, T const& value, Compare comp);
Requires
========================================
| The elements e of [first,last) shall be partitioned with respect to the expression ``!(value < e)`` or ``!comp(value, e)``.
Returns
========================================
| The furthermost iterator i in the range [first,last] such that for any iterator j in the range [first,i) the following corresponding conditions hold: ``!(value < *j)`` or ``!comp(value, *j)``.
Examples
========================================
.. sourcecode:: c++
#include <sprout/algorithm/upper_bound.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::upper_bound(begin(input), end(input), 5);
static_assert(result - begin(input) == 7, "a upper bound position is 7.");
Complexity
========================================
| At most ``log2(last - first) + O(1)`` comparisons.
| Recursive function invocations in *O(logN)* (logarithmic) depth.
Header
========================================
| ``sprout/algorithm/upper_bound.hpp``
| Convenience header: ``sprout/algorithm.hpp``

View file

@ -52,20 +52,29 @@
</ul>
<div class="section" id="welcome-to-the-sprout-c-libraries">
<h2>Welcome to the Sprout C++ Libraries<a class="headerlink" href="#welcome-to-the-sprout-c-libraries" title="Permalink to this headline"></a></h2>
<p>C++11 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others.</p>
<div class="line-block">
<div class="line">C++11 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others.</div>
</div>
</div>
<div class="section" id="library-documentation">
<h2>Library Documentation<a class="headerlink" href="#library-documentation" title="Permalink to this headline"></a></h2>
<p>The starting point for the documentation of individual libraries is the <a class="reference external" href="libraries.html"><em>Libraries page</em></a>, which gives a brief description of each library and links to its documentation.</p>
<div class="line-block">
<div class="line">The starting point for the documentation of individual libraries is the <a class="reference external" href="libraries.html"><em>Libraries page</em></a>, which gives a brief description of each library and links to its documentation.</div>
</div>
</div>
<div class="section" id="project-page">
<h2>Project page<a class="headerlink" href="#project-page" title="Permalink to this headline"></a></h2>
<p>Github: <a class="reference external" href="https://github.com/bolero-MURAKAMI/Sprout">https://github.com/bolero-MURAKAMI/Sprout</a></p>
<ul class="simple">
<li><a class="reference external" href="http://bolero-murakami.github.io/Sprout/">Project page</a></li>
<li><a class="reference external" href="https://github.com/bolero-MURAKAMI/Sprout/">Repository (Github)</a></li>
</ul>
</div>
<div class="section" id="install">
<h2>Install<a class="headerlink" href="#install" title="Permalink to this headline"></a></h2>
<p>Through the path to the directory. <tt class="docutils literal"><span class="pre">/path/to/sprout</span></tt></p>
<p>This library can be used in the header only.</p>
<div class="line-block">
<div class="line">Through the path to the directory. <tt class="docutils literal"><span class="pre">/path/to/sprout</span></tt></div>
<div class="line">This library can be used in the header only.</div>
</div>
</div>
<div class="section" id="supported-compilers">
<h2>Supported Compilers<a class="headerlink" href="#supported-compilers" title="Permalink to this headline"></a></h2>
@ -77,22 +86,18 @@
</div>
<div class="section" id="author">
<h2>Author<a class="headerlink" href="#author" title="Permalink to this headline"></a></h2>
<p>Bolero MURAKAMI</p>
<ul class="simple">
<li>Website: <a class="reference external" href="http://www.boleros.x0.com/">http://www.boleros.x0.com/</a></li>
<li>Twitter: <a class="reference external" href="https://twitter.com/bolero_murakami">https://twitter.com/bolero_murakami</a></li>
<li>Facebook: <a class="reference external" href="http://www.facebook.com/genya.murakami">http://www.facebook.com/genya.murakami</a></li>
<li>Blog: <a class="reference external" href="http://d.hatena.ne.jp/boleros/">http://d.hatena.ne.jp/boleros/</a></li>
<li>Github: <a class="reference external" href="https://github.com/bolero-MURAKAMI">https://github.com/bolero-MURAKAMI</a></li>
<li>SlideShare: <a class="reference external" href="http://www.slideshare.net/GenyaMurakami">http://www.slideshare.net/GenyaMurakami</a></li>
<li>Mail: <a class="reference external" href="mailto:contact-lib&#37;&#52;&#48;boleros&#46;x0&#46;com">contact-lib<span>&#64;</span>boleros<span>&#46;</span>x0<span>&#46;</span>com</a></li>
</ul>
<div class="line-block">
<div class="line">Bolero MURAKAMI <a class="reference external" href="mailto:contact-lib&#37;&#52;&#48;boleros&#46;x0&#46;com">(Mail)</a></div>
<div class="line"><a class="reference external" href="http://bolero-murakami.github.io/">[Website]</a> <a class="reference external" href="https://twitter.com/bolero_murakami">[Twitter]</a> <a class="reference external" href="http://www.facebook.com/genya.murakami">[Facebook]</a> <a class="reference external" href="http://d.hatena.ne.jp/boleros/">[Blog]</a> <a class="reference external" href="https://github.com/bolero-MURAKAMI">[Github]</a> <a class="reference external" href="http://www.slideshare.net/GenyaMurakami">[SlideShare]</a></div>
</div>
</div>
<div class="section" id="copyrights">
<h2>Copyrights<a class="headerlink" href="#copyrights" title="Permalink to this headline"></a></h2>
<p>Copyright (C) 2011-2013 Bolero MURAKAMI.</p>
<p>Distributed under the Boost Software License, Version 1.0.</p>
<p>(See accompanying file LICENSE_1_0.txt or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</p>
<div class="line-block">
<div class="line">Copyright (C) 2011-2013 Bolero MURAKAMI.</div>
<div class="line">Distributed under the Boost Software License, Version 1.0.</div>
<div class="line">(See accompanying file LICENSE_1_0.txt or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</div>
</div>
</div>
</div>

View file

@ -0,0 +1,168 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>binary_search &mdash; Sprout v1.0 documentation</title>
<link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../../_static/jquery.js"></script>
<script type="text/javascript" src="../../../_static/doctools.js"></script>
<link rel="top" title="Sprout v1.0 documentation" href="../../../index.html" />
<link rel="up" title="Sprout.Algorithm" href="index.html" />
<link rel="prev" title="equal_range" href="equal_range.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="equal_range.html" title="equal_range"
accesskey="P">previous</a> |</li>
<li><a href="../../../index.html">Sprout v1.0 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Sprout C++ Libraries</a> &raquo;</li>
<li><a href="../../libraries.html" >Libraries</a> &raquo;</li>
<li><a href="index.html" accesskey="U">Sprout.Algorithm</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="binary-search">
<h1>binary_search<a class="headerlink" href="#binary-search" title="Permalink to this headline"></a></h1>
<div class="section" id="interface">
<h2>Interface<a class="headerlink" href="#interface" title="Permalink to this headline"></a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">ForwardIterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">SPROUT_CONSTEXPR</span> <span class="kt">bool</span>
<span class="n">binary_search</span><span class="p">(</span><span class="n">ForwardIterator</span> <span class="n">first</span><span class="p">,</span> <span class="n">ForwardIterator</span> <span class="n">last</span><span class="p">,</span> <span class="n">T</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">value</span><span class="p">);</span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">ForwardIterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">T</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Compare</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">SPROUT_CONSTEXPR</span> <span class="kt">bool</span>
<span class="n">binary_search</span><span class="p">(</span><span class="n">ForwardIterator</span> <span class="n">first</span><span class="p">,</span> <span class="n">ForwardIterator</span> <span class="n">last</span><span class="p">,</span> <span class="n">T</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">value</span><span class="p">,</span> <span class="n">Compare</span> <span class="n">comp</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="requires">
<h2>Requires<a class="headerlink" href="#requires" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">The elements e of [first,last) are partitioned with respect to the expressions <tt class="docutils literal"><span class="pre">e</span> <span class="pre">&lt;</span> <span class="pre">value</span></tt> and <tt class="docutils literal"><span class="pre">!(value</span> <span class="pre">&lt;</span> <span class="pre">e)</span></tt> or <tt class="docutils literal"><span class="pre">comp(e,</span> <span class="pre">value)</span></tt> and <tt class="docutils literal"><span class="pre">!comp(value,</span> <span class="pre">e)</span></tt>.</div>
<div class="line">Also, for all elements e of [first,last), <tt class="docutils literal"><span class="pre">e</span> <span class="pre">&lt;</span> <span class="pre">value</span></tt> implies <tt class="docutils literal"><span class="pre">!(value</span> <span class="pre">&lt;</span> <span class="pre">e)</span></tt> or <tt class="docutils literal"><span class="pre">comp(e,</span> <span class="pre">value)</span></tt> implies <tt class="docutils literal"><span class="pre">!comp(value,</span> <span class="pre">e)</span></tt>.</div>
</div>
</div>
<div class="section" id="returns">
<h2>Returns<a class="headerlink" href="#returns" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">true if there is an iterator i in the range [first,last) that satisfies the corresponding conditions: <tt class="docutils literal"><span class="pre">!(*i</span> <span class="pre">&lt;</span> <span class="pre">value)</span> <span class="pre">&amp;&amp;</span> <span class="pre">!(value</span> <span class="pre">&lt;</span> <span class="pre">*i)</span></tt> or <tt class="docutils literal"><span class="pre">comp(*i,</span> <span class="pre">value)</span> <span class="pre">&amp;&amp;</span> <span class="pre">comp(value,</span> <span class="pre">*i)</span></tt>.</div>
</div>
</div>
<div class="section" id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;sprout/algorithm/binary_search.hpp&gt;</span>
<span class="cp">#include &lt;sprout/array.hpp&gt;</span>
<span class="cp">#include &lt;sprout/container.hpp&gt;</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">sprout</span><span class="p">;</span>
<span class="n">SPROUT_STATIC_CONSTEXPR</span> <span class="k">auto</span> <span class="n">input</span> <span class="o">=</span> <span class="n">array</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">,</span> <span class="mi">10</span><span class="o">&gt;</span><span class="p">{{</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">}};</span>
<span class="n">SPROUT_STATIC_CONSTEXPR</span> <span class="k">auto</span> <span class="n">result</span> <span class="o">=</span> <span class="n">sprout</span><span class="o">::</span><span class="n">binary_search</span><span class="p">(</span><span class="n">begin</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="n">end</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="mi">5</span><span class="p">);</span>
<span class="n">static_assert</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="s">&quot;found 5 by binary search.&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="complexity">
<h2>Complexity<a class="headerlink" href="#complexity" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">At most <tt class="docutils literal"><span class="pre">log2(last</span> <span class="pre">-</span> <span class="pre">first)</span> <span class="pre">+</span> <span class="pre">O(1)</span></tt> comparisons.</div>
<div class="line">Recursive function invocations in <em>O(logN)</em> (logarithmic) depth.</div>
</div>
</div>
<div class="section" id="header">
<h2>Header<a class="headerlink" href="#header" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line"><tt class="docutils literal"><span class="pre">sprout/algorithm/binary_search.hpp</span></tt></div>
<div class="line">Convenience header: <tt class="docutils literal"><span class="pre">sprout/algorithm.hpp</span></tt></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../../../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href="#">binary_search</a><ul>
<li><a class="reference external" href="#interface">Interface</a></li>
<li><a class="reference external" href="#requires">Requires</a></li>
<li><a class="reference external" href="#returns">Returns</a></li>
<li><a class="reference external" href="#examples">Examples</a></li>
<li><a class="reference external" href="#complexity">Complexity</a></li>
<li><a class="reference external" href="#header">Header</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="equal_range.html"
title="previous chapter">equal_range</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../../_sources/libs/sprout/algorithm/binary_search.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="equal_range.html" title="equal_range"
>previous</a> |</li>
<li><a href="../../../index.html">Sprout v1.0 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Sprout C++ Libraries</a> &raquo;</li>
<li><a href="../../libraries.html" >Libraries</a> &raquo;</li>
<li><a href="index.html" >Sprout.Algorithm</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2013, Bolero MURAKAMI.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
</div>
</body>
</html>

View file

@ -0,0 +1,183 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>equal_range &mdash; Sprout v1.0 documentation</title>
<link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../../_static/jquery.js"></script>
<script type="text/javascript" src="../../../_static/doctools.js"></script>
<link rel="top" title="Sprout v1.0 documentation" href="../../../index.html" />
<link rel="up" title="Sprout.Algorithm" href="index.html" />
<link rel="next" title="binary_search" href="binary_search.html" />
<link rel="prev" title="upper_bound" href="upper_bound.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="binary_search.html" title="binary_search"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="upper_bound.html" title="upper_bound"
accesskey="P">previous</a> |</li>
<li><a href="../../../index.html">Sprout v1.0 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Sprout C++ Libraries</a> &raquo;</li>
<li><a href="../../libraries.html" >Libraries</a> &raquo;</li>
<li><a href="index.html" accesskey="U">Sprout.Algorithm</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="equal-range">
<h1>equal_range<a class="headerlink" href="#equal-range" title="Permalink to this headline"></a></h1>
<div class="section" id="interface">
<h2>Interface<a class="headerlink" href="#interface" title="Permalink to this headline"></a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">ForwardIterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">SPROUT_CONSTEXPR</span> <span class="n">sprout</span><span class="o">::</span><span class="n">pair</span><span class="o">&lt;</span><span class="n">ForwardIterator</span><span class="p">,</span> <span class="n">ForwardIterator</span><span class="o">&gt;</span>
<span class="n">equal_range</span><span class="p">(</span><span class="n">ForwardIterator</span> <span class="n">first</span><span class="p">,</span> <span class="n">ForwardIterator</span> <span class="n">last</span><span class="p">,</span> <span class="n">T</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">value</span><span class="p">);</span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">ForwardIterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">T</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Compare</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">SPROUT_CONSTEXPR</span> <span class="n">sprout</span><span class="o">::</span><span class="n">pair</span><span class="o">&lt;</span><span class="n">ForwardIterator</span><span class="p">,</span> <span class="n">ForwardIterator</span><span class="o">&gt;</span>
<span class="n">equal_range</span><span class="p">(</span><span class="n">ForwardIterator</span> <span class="n">first</span><span class="p">,</span> <span class="n">ForwardIterator</span> <span class="n">last</span><span class="p">,</span> <span class="n">T</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">value</span><span class="p">,</span> <span class="n">Compare</span> <span class="n">comp</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="requires">
<h2>Requires<a class="headerlink" href="#requires" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">The elements e of [first,last) shall be partitioned with respect to the expressions <tt class="docutils literal"><span class="pre">e</span> <span class="pre">&lt;</span> <span class="pre">value</span></tt> and <tt class="docutils literal"><span class="pre">!(value</span> <span class="pre">&lt;</span> <span class="pre">e)</span></tt> or <tt class="docutils literal"><span class="pre">comp(e,</span> <span class="pre">value)</span></tt> and <tt class="docutils literal"><span class="pre">!comp(value,</span> <span class="pre">e)</span></tt>.</div>
<div class="line">Also, for all elements e of [first, last), <tt class="docutils literal"><span class="pre">e</span> <span class="pre">&lt;</span> <span class="pre">value</span></tt> shall imply <tt class="docutils literal"><span class="pre">!(value</span> <span class="pre">&lt;</span> <span class="pre">e)</span></tt> or <tt class="docutils literal"><span class="pre">comp(e,</span> <span class="pre">value)</span></tt> shall imply <tt class="docutils literal"><span class="pre">!comp(value,</span> <span class="pre">e)</span></tt>.</div>
</div>
</div>
<div class="section" id="returns">
<h2>Returns<a class="headerlink" href="#returns" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line"><tt class="docutils literal"><span class="pre">make_pair(lower_bound(first,</span> <span class="pre">last,</span> <span class="pre">value),</span> <span class="pre">upper_bound(first,</span> <span class="pre">last,</span> <span class="pre">value))</span></tt></div>
<div class="line">or</div>
<div class="line"><tt class="docutils literal"><span class="pre">make_pair(lower_bound(first,</span> <span class="pre">last,</span> <span class="pre">value,</span> <span class="pre">comp),</span> <span class="pre">upper_bound(first,</span> <span class="pre">last,</span> <span class="pre">value,</span> <span class="pre">comp))</span></tt></div>
</div>
</div>
<div class="section" id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;sprout/algorithm/equal_range.hpp&gt;</span>
<span class="cp">#include &lt;sprout/algorithm/all_of_equal.hpp&gt;</span>
<span class="cp">#include &lt;sprout/array.hpp&gt;</span>
<span class="cp">#include &lt;sprout/container.hpp&gt;</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">sprout</span><span class="p">;</span>
<span class="n">SPROUT_STATIC_CONSTEXPR</span> <span class="k">auto</span> <span class="n">input</span> <span class="o">=</span> <span class="n">array</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">,</span> <span class="mi">10</span><span class="o">&gt;</span><span class="p">{{</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">}};</span>
<span class="n">SPROUT_STATIC_CONSTEXPR</span> <span class="k">auto</span> <span class="n">result</span> <span class="o">=</span> <span class="n">sprout</span><span class="o">::</span><span class="n">equal_range</span><span class="p">(</span><span class="n">begin</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="n">end</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="mi">5</span><span class="p">);</span>
<span class="n">static_assert</span><span class="p">(</span><span class="n">result</span><span class="p">.</span><span class="n">first</span> <span class="o">-</span> <span class="n">begin</span><span class="p">(</span><span class="n">input</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">,</span> <span class="s">&quot;a lower bound position is 3.&quot;</span><span class="p">);</span>
<span class="n">static_assert</span><span class="p">(</span><span class="n">result</span><span class="p">.</span><span class="n">second</span> <span class="o">-</span> <span class="n">begin</span><span class="p">(</span><span class="n">input</span><span class="p">)</span> <span class="o">==</span> <span class="mi">7</span><span class="p">,</span> <span class="s">&quot;a upper bound position is 7.&quot;</span><span class="p">);</span>
<span class="n">static_assert</span><span class="p">(</span><span class="n">sprout</span><span class="o">::</span><span class="n">all_of_equal</span><span class="p">(</span><span class="n">result</span><span class="p">.</span><span class="n">first</span><span class="p">,</span> <span class="n">result</span><span class="p">.</span><span class="n">second</span><span class="p">.</span> <span class="mi">5</span><span class="p">),</span> <span class="s">&quot;all of result range is equal to 5.&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="complexity">
<h2>Complexity<a class="headerlink" href="#complexity" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">At most <tt class="docutils literal"><span class="pre">2</span> <span class="pre">*</span> <span class="pre">log2(last</span> <span class="pre">-</span> <span class="pre">first)</span> <span class="pre">+</span> <span class="pre">O(1)</span></tt> comparisons.</div>
<div class="line">Recursive function invocations in <em>O(logN)</em> (logarithmic) depth.</div>
</div>
</div>
<div class="section" id="header">
<h2>Header<a class="headerlink" href="#header" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line"><tt class="docutils literal"><span class="pre">sprout/algorithm/equal_range.hpp</span></tt></div>
<div class="line">Convenience header: <tt class="docutils literal"><span class="pre">sprout/algorithm.hpp</span></tt></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../../../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href="#">equal_range</a><ul>
<li><a class="reference external" href="#interface">Interface</a></li>
<li><a class="reference external" href="#requires">Requires</a></li>
<li><a class="reference external" href="#returns">Returns</a></li>
<li><a class="reference external" href="#examples">Examples</a></li>
<li><a class="reference external" href="#complexity">Complexity</a></li>
<li><a class="reference external" href="#header">Header</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="upper_bound.html"
title="previous chapter">upper_bound</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="binary_search.html"
title="next chapter">binary_search</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../../_sources/libs/sprout/algorithm/equal_range.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="binary_search.html" title="binary_search"
>next</a> |</li>
<li class="right" >
<a href="upper_bound.html" title="upper_bound"
>previous</a> |</li>
<li><a href="../../../index.html">Sprout v1.0 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Sprout C++ Libraries</a> &raquo;</li>
<li><a href="../../libraries.html" >Libraries</a> &raquo;</li>
<li><a href="index.html" >Sprout.Algorithm</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2013, Bolero MURAKAMI.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
</div>
</body>
</html>

View file

@ -89,10 +89,10 @@
<div class="section" id="binary-search">
<h3>Binary search<a class="headerlink" href="#binary-search" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li><tt class="xref docutils literal"><span class="pre">lower_bound</span></tt></li>
<li><tt class="xref docutils literal"><span class="pre">upper_bound</span></tt></li>
<li><tt class="xref docutils literal"><span class="pre">equal_range</span></tt></li>
<li><tt class="xref docutils literal"><span class="pre">binary_search</span></tt></li>
<li><a class="reference external" href="lower_bound.html"><em>lower_bound</em></a></li>
<li><a class="reference external" href="upper_bound.html"><em>upper_bound</em></a></li>
<li><a class="reference external" href="equal_range.html"><em>equal_range</em></a></li>
<li><a class="reference external" href="binary_search.html"><em>binary_search</em></a></li>
</ul>
</div>
<div class="section" id="heap-operations">

View file

@ -21,6 +21,7 @@
<script type="text/javascript" src="../../../_static/doctools.js"></script>
<link rel="top" title="Sprout v1.0 documentation" href="../../../index.html" />
<link rel="up" title="Sprout.Algorithm" href="index.html" />
<link rel="next" title="lower_bound" href="lower_bound.html" />
<link rel="prev" title="is_strictly_increasing" href="is_strictly_increasing.html" />
</head>
<body>
@ -30,6 +31,9 @@
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="lower_bound.html" title="lower_bound"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="is_strictly_increasing.html" title="is_strictly_increasing"
accesskey="P">previous</a> |</li>
@ -110,6 +114,9 @@
<h4>Previous topic</h4>
<p class="topless"><a href="is_strictly_increasing.html"
title="previous chapter">is_strictly_increasing</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="lower_bound.html"
title="next chapter">lower_bound</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../../_sources/libs/sprout/algorithm/is_strictly_decreasing.txt"
@ -138,6 +145,9 @@
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="lower_bound.html" title="lower_bound"
>next</a> |</li>
<li class="right" >
<a href="is_strictly_increasing.html" title="is_strictly_increasing"
>previous</a> |</li>

View file

@ -0,0 +1,177 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>lower_bound &mdash; Sprout v1.0 documentation</title>
<link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../../_static/jquery.js"></script>
<script type="text/javascript" src="../../../_static/doctools.js"></script>
<link rel="top" title="Sprout v1.0 documentation" href="../../../index.html" />
<link rel="up" title="Sprout.Algorithm" href="index.html" />
<link rel="next" title="upper_bound" href="upper_bound.html" />
<link rel="prev" title="is_strictly_decreasing" href="is_strictly_decreasing.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="upper_bound.html" title="upper_bound"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="is_strictly_decreasing.html" title="is_strictly_decreasing"
accesskey="P">previous</a> |</li>
<li><a href="../../../index.html">Sprout v1.0 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Sprout C++ Libraries</a> &raquo;</li>
<li><a href="../../libraries.html" >Libraries</a> &raquo;</li>
<li><a href="index.html" accesskey="U">Sprout.Algorithm</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="lower-bound">
<h1>lower_bound<a class="headerlink" href="#lower-bound" title="Permalink to this headline"></a></h1>
<div class="section" id="interface">
<h2>Interface<a class="headerlink" href="#interface" title="Permalink to this headline"></a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">ForwardIterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">SPROUT_CONSTEXPR</span> <span class="n">ForwardIterator</span>
<span class="n">lower_bound</span><span class="p">(</span><span class="n">ForwardIterator</span> <span class="n">first</span><span class="p">,</span> <span class="n">ForwardIterator</span> <span class="n">last</span><span class="p">,</span> <span class="n">T</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">value</span><span class="p">);</span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">ForwardIterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">T</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Compare</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">SPROUT_CONSTEXPR</span> <span class="n">ForwardIterator</span>
<span class="n">lower_bound</span><span class="p">(</span><span class="n">ForwardIterator</span> <span class="n">first</span><span class="p">,</span> <span class="n">ForwardIterator</span> <span class="n">last</span><span class="p">,</span> <span class="n">T</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">value</span><span class="p">,</span> <span class="n">Compare</span> <span class="n">comp</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="requires">
<h2>Requires<a class="headerlink" href="#requires" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">The elements e of [first,last) shall be partitioned with respect to the expression <tt class="docutils literal"><span class="pre">e</span> <span class="pre">&lt;</span> <span class="pre">value</span></tt> or <tt class="docutils literal"><span class="pre">comp(e,</span> <span class="pre">value)</span></tt>.</div>
</div>
</div>
<div class="section" id="returns">
<h2>Returns<a class="headerlink" href="#returns" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">The furthermost iterator i in the range [first,last] such that for any iterator j in the range [first,i) the following corresponding conditions hold: <tt class="docutils literal"><span class="pre">*j</span> <span class="pre">&lt;</span> <span class="pre">value</span></tt> or <tt class="docutils literal"><span class="pre">comp(*j,</span> <span class="pre">value)</span></tt>.</div>
</div>
</div>
<div class="section" id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;sprout/algorithm/lower_bound.hpp&gt;</span>
<span class="cp">#include &lt;sprout/array.hpp&gt;</span>
<span class="cp">#include &lt;sprout/container.hpp&gt;</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">sprout</span><span class="p">;</span>
<span class="n">SPROUT_STATIC_CONSTEXPR</span> <span class="k">auto</span> <span class="n">input</span> <span class="o">=</span> <span class="n">array</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">,</span> <span class="mi">10</span><span class="o">&gt;</span><span class="p">{{</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">}};</span>
<span class="n">SPROUT_STATIC_CONSTEXPR</span> <span class="k">auto</span> <span class="n">result</span> <span class="o">=</span> <span class="n">sprout</span><span class="o">::</span><span class="n">lower_bound</span><span class="p">(</span><span class="n">begin</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="n">end</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="mi">5</span><span class="p">);</span>
<span class="n">static_assert</span><span class="p">(</span><span class="n">result</span> <span class="o">-</span> <span class="n">begin</span><span class="p">(</span><span class="n">input</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">,</span> <span class="s">&quot;a lower bound position is 3.&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="complexity">
<h2>Complexity<a class="headerlink" href="#complexity" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">At most <tt class="docutils literal"><span class="pre">log2(last</span> <span class="pre">-</span> <span class="pre">first)</span> <span class="pre">+</span> <span class="pre">O(1)</span></tt> comparisons.</div>
<div class="line">Recursive function invocations in <em>O(logN)</em> (logarithmic) depth.</div>
</div>
</div>
<div class="section" id="header">
<h2>Header<a class="headerlink" href="#header" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line"><tt class="docutils literal"><span class="pre">sprout/algorithm/lower_bound.hpp</span></tt></div>
<div class="line">Convenience header: <tt class="docutils literal"><span class="pre">sprout/algorithm.hpp</span></tt></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../../../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href="#">lower_bound</a><ul>
<li><a class="reference external" href="#interface">Interface</a></li>
<li><a class="reference external" href="#requires">Requires</a></li>
<li><a class="reference external" href="#returns">Returns</a></li>
<li><a class="reference external" href="#examples">Examples</a></li>
<li><a class="reference external" href="#complexity">Complexity</a></li>
<li><a class="reference external" href="#header">Header</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="is_strictly_decreasing.html"
title="previous chapter">is_strictly_decreasing</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="upper_bound.html"
title="next chapter">upper_bound</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../../_sources/libs/sprout/algorithm/lower_bound.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="upper_bound.html" title="upper_bound"
>next</a> |</li>
<li class="right" >
<a href="is_strictly_decreasing.html" title="is_strictly_decreasing"
>previous</a> |</li>
<li><a href="../../../index.html">Sprout v1.0 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Sprout C++ Libraries</a> &raquo;</li>
<li><a href="../../libraries.html" >Libraries</a> &raquo;</li>
<li><a href="index.html" >Sprout.Algorithm</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2013, Bolero MURAKAMI.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
</div>
</body>
</html>

View file

@ -0,0 +1,177 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upper_bound &mdash; Sprout v1.0 documentation</title>
<link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../',
VERSION: '1.0',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../../_static/jquery.js"></script>
<script type="text/javascript" src="../../../_static/doctools.js"></script>
<link rel="top" title="Sprout v1.0 documentation" href="../../../index.html" />
<link rel="up" title="Sprout.Algorithm" href="index.html" />
<link rel="next" title="equal_range" href="equal_range.html" />
<link rel="prev" title="lower_bound" href="lower_bound.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="equal_range.html" title="equal_range"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="lower_bound.html" title="lower_bound"
accesskey="P">previous</a> |</li>
<li><a href="../../../index.html">Sprout v1.0 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Sprout C++ Libraries</a> &raquo;</li>
<li><a href="../../libraries.html" >Libraries</a> &raquo;</li>
<li><a href="index.html" accesskey="U">Sprout.Algorithm</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="upper-bound">
<h1>upper_bound<a class="headerlink" href="#upper-bound" title="Permalink to this headline"></a></h1>
<div class="section" id="interface">
<h2>Interface<a class="headerlink" href="#interface" title="Permalink to this headline"></a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">ForwardIterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">SPROUT_CONSTEXPR</span> <span class="n">ForwardIterator</span>
<span class="n">upper_bound</span><span class="p">(</span><span class="n">ForwardIterator</span> <span class="n">first</span><span class="p">,</span> <span class="n">ForwardIterator</span> <span class="n">last</span><span class="p">,</span> <span class="n">T</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">value</span><span class="p">);</span>
<span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">ForwardIterator</span><span class="p">,</span> <span class="k">typename</span> <span class="n">T</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Compare</span><span class="o">&gt;</span>
<span class="kr">inline</span> <span class="n">SPROUT_CONSTEXPR</span> <span class="n">ForwardIterator</span>
<span class="n">upper_bound</span><span class="p">(</span><span class="n">ForwardIterator</span> <span class="n">first</span><span class="p">,</span> <span class="n">ForwardIterator</span> <span class="n">last</span><span class="p">,</span> <span class="n">T</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">value</span><span class="p">,</span> <span class="n">Compare</span> <span class="n">comp</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="requires">
<h2>Requires<a class="headerlink" href="#requires" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">The elements e of [first,last) shall be partitioned with respect to the expression <tt class="docutils literal"><span class="pre">!(value</span> <span class="pre">&lt;</span> <span class="pre">e)</span></tt> or <tt class="docutils literal"><span class="pre">!comp(value,</span> <span class="pre">e)</span></tt>.</div>
</div>
</div>
<div class="section" id="returns">
<h2>Returns<a class="headerlink" href="#returns" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">The furthermost iterator i in the range [first,last] such that for any iterator j in the range [first,i) the following corresponding conditions hold: <tt class="docutils literal"><span class="pre">!(value</span> <span class="pre">&lt;</span> <span class="pre">*j)</span></tt> or <tt class="docutils literal"><span class="pre">!comp(value,</span> <span class="pre">*j)</span></tt>.</div>
</div>
</div>
<div class="section" id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span class="cp">#include &lt;sprout/algorithm/upper_bound.hpp&gt;</span>
<span class="cp">#include &lt;sprout/array.hpp&gt;</span>
<span class="cp">#include &lt;sprout/container.hpp&gt;</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">sprout</span><span class="p">;</span>
<span class="n">SPROUT_STATIC_CONSTEXPR</span> <span class="k">auto</span> <span class="n">input</span> <span class="o">=</span> <span class="n">array</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">,</span> <span class="mi">10</span><span class="o">&gt;</span><span class="p">{{</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">}};</span>
<span class="n">SPROUT_STATIC_CONSTEXPR</span> <span class="k">auto</span> <span class="n">result</span> <span class="o">=</span> <span class="n">sprout</span><span class="o">::</span><span class="n">upper_bound</span><span class="p">(</span><span class="n">begin</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="n">end</span><span class="p">(</span><span class="n">input</span><span class="p">),</span> <span class="mi">5</span><span class="p">);</span>
<span class="n">static_assert</span><span class="p">(</span><span class="n">result</span> <span class="o">-</span> <span class="n">begin</span><span class="p">(</span><span class="n">input</span><span class="p">)</span> <span class="o">==</span> <span class="mi">7</span><span class="p">,</span> <span class="s">&quot;a upper bound position is 7.&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="complexity">
<h2>Complexity<a class="headerlink" href="#complexity" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line">At most <tt class="docutils literal"><span class="pre">log2(last</span> <span class="pre">-</span> <span class="pre">first)</span> <span class="pre">+</span> <span class="pre">O(1)</span></tt> comparisons.</div>
<div class="line">Recursive function invocations in <em>O(logN)</em> (logarithmic) depth.</div>
</div>
</div>
<div class="section" id="header">
<h2>Header<a class="headerlink" href="#header" title="Permalink to this headline"></a></h2>
<div class="line-block">
<div class="line"><tt class="docutils literal"><span class="pre">sprout/algorithm/upper_bound.hpp</span></tt></div>
<div class="line">Convenience header: <tt class="docutils literal"><span class="pre">sprout/algorithm.hpp</span></tt></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../../../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference external" href="#">upper_bound</a><ul>
<li><a class="reference external" href="#interface">Interface</a></li>
<li><a class="reference external" href="#requires">Requires</a></li>
<li><a class="reference external" href="#returns">Returns</a></li>
<li><a class="reference external" href="#examples">Examples</a></li>
<li><a class="reference external" href="#complexity">Complexity</a></li>
<li><a class="reference external" href="#header">Header</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="lower_bound.html"
title="previous chapter">lower_bound</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="equal_range.html"
title="next chapter">equal_range</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../../_sources/libs/sprout/algorithm/upper_bound.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="equal_range.html" title="equal_range"
>next</a> |</li>
<li class="right" >
<a href="lower_bound.html" title="lower_bound"
>previous</a> |</li>
<li><a href="../../../index.html">Sprout v1.0 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Sprout C++ Libraries</a> &raquo;</li>
<li><a href="../../libraries.html" >Libraries</a> &raquo;</li>
<li><a href="index.html" >Sprout.Algorithm</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2013, Bolero MURAKAMI.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
</div>
</body>
</html>

File diff suppressed because one or more lines are too long

View file

@ -40,7 +40,7 @@
<p>C++11 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others.</p>
<p>
<a href="./docs/index.html" class="btn btn-info btn-large">Documentation &raquo;</a>
<a href="https://github.com/bolero-MURAKAMI/Sprout/" class="btn btn-primary btn-large" target="_blank">Project page (Github) &raquo;</a>
<a href="https://github.com/bolero-MURAKAMI/Sprout/" class="btn btn-primary btn-large" target="_blank">Repository (Github) &raquo;</a>
</p>
</div>

View file

@ -13,30 +13,30 @@ Sprout C++ Libraries
Welcome to the Sprout C++ Libraries
*******************************************************************************
C++11 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others.
| C++11 constexpr based Containers, Algorithms, Random numbers, Parsing, Ray tracing, Synthesizer, and others.
.. _sprout-documentation:
*******************************************************************************
Library Documentation
*******************************************************************************
The starting point for the documentation of individual libraries is the :doc:`Libraries page <./libraries>`, which gives a brief description of each library and links to its documentation.
| The starting point for the documentation of individual libraries is the :doc:`Libraries page <./libraries>`, which gives a brief description of each library and links to its documentation.
.. _sprout-project:
*******************************************************************************
Project page
*******************************************************************************
Github: https://github.com/bolero-MURAKAMI/Sprout
* `Project page <http://bolero-murakami.github.io/Sprout/>`_
* `Repository (Github) <https://github.com/bolero-MURAKAMI/Sprout/>`_
.. _sprout-install:
*******************************************************************************
Install
*******************************************************************************
Through the path to the directory. ``/path/to/sprout``
This library can be used in the header only.
| Through the path to the directory. ``/path/to/sprout``
| This library can be used in the header only.
.. _sprout-compilers:
*******************************************************************************
@ -46,7 +46,6 @@ Supported Compilers
Linux:
* GCC, C++11 mode: 4.7.0, 4.7.1, 4.7.2, 4.7.3, 4.8.0, 4.8.1
* Clang, C++11 mode: 3.2, 3.3
.. _sprout-author:
@ -54,30 +53,15 @@ Linux:
Author
*******************************************************************************
Bolero MURAKAMI
* Website: http://www.boleros.x0.com/
* Twitter: https://twitter.com/bolero_murakami
* Facebook: http://www.facebook.com/genya.murakami
* Blog: http://d.hatena.ne.jp/boleros/
* Github: https://github.com/bolero-MURAKAMI
* SlideShare: http://www.slideshare.net/GenyaMurakami
* Mail: contact-lib@boleros.x0.com
| Bolero MURAKAMI `(Mail) <contact-lib@boleros.x0.com>`_
| `[Website] <http://bolero-murakami.github.io/>`_ `[Twitter] <https://twitter.com/bolero_murakami>`_ `[Facebook] <http://www.facebook.com/genya.murakami>`_ `[Blog] <http://d.hatena.ne.jp/boleros/>`_ `[Github] <https://github.com/bolero-MURAKAMI>`_ `[SlideShare] <http://www.slideshare.net/GenyaMurakami>`_
.. _sprout-copyrights:
*******************************************************************************
Copyrights
*******************************************************************************
Copyright (C) 2011-2013 Bolero MURAKAMI.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
| Copyright (C) 2011-2013 Bolero MURAKAMI.
| Distributed under the Boost Software License, Version 1.0.
| (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View file

@ -0,0 +1,53 @@
.. _sprout-algorithm-binary_search:
###############################################################################
binary_search
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<typename ForwardIterator, typename T>
inline SPROUT_CONSTEXPR bool
binary_search(ForwardIterator first, ForwardIterator last, T const& value);
template<typename ForwardIterator, typename T, typename Compare>
inline SPROUT_CONSTEXPR bool
binary_search(ForwardIterator first, ForwardIterator last, T const& value, Compare comp);
Requires
========================================
| The elements e of [first,last) are partitioned with respect to the expressions ``e < value`` and ``!(value < e)`` or ``comp(e, value)`` and ``!comp(value, e)``.
| Also, for all elements e of [first,last), ``e < value`` implies ``!(value < e)`` or ``comp(e, value)`` implies ``!comp(value, e)``.
Returns
========================================
| true if there is an iterator i in the range [first,last) that satisfies the corresponding conditions: ``!(*i < value) && !(value < *i)`` or ``comp(*i, value) && comp(value, *i)``.
Examples
========================================
.. sourcecode:: c++
#include <sprout/algorithm/binary_search.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::binary_search(begin(input), end(input), 5);
static_assert(result, "found 5 by binary search.");
Complexity
========================================
| At most ``log2(last - first) + O(1)`` comparisons.
| Recursive function invocations in *O(logN)* (logarithmic) depth.
Header
========================================
| ``sprout/algorithm/binary_search.hpp``
| Convenience header: ``sprout/algorithm.hpp``

View file

@ -0,0 +1,58 @@
.. _sprout-algorithm-equal_range:
###############################################################################
equal_range
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<typename ForwardIterator, typename T>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
equal_range(ForwardIterator first, ForwardIterator last, T const& value);
template<typename ForwardIterator, typename T, typename Compare>
inline SPROUT_CONSTEXPR sprout::pair<ForwardIterator, ForwardIterator>
equal_range(ForwardIterator first, ForwardIterator last, T const& value, Compare comp);
Requires
========================================
| The elements e of [first,last) shall be partitioned with respect to the expressions ``e < value`` and ``!(value < e)`` or ``comp(e, value)`` and ``!comp(value, e)``.
| Also, for all elements e of [first, last), ``e < value`` shall imply ``!(value < e)`` or ``comp(e, value)`` shall imply ``!comp(value, e)``.
Returns
========================================
| ``make_pair(lower_bound(first, last, value), upper_bound(first, last, value))``
| or
| ``make_pair(lower_bound(first, last, value, comp), upper_bound(first, last, value, comp))``
Examples
========================================
.. sourcecode:: c++
#include <sprout/algorithm/equal_range.hpp>
#include <sprout/algorithm/all_of_equal.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::equal_range(begin(input), end(input), 5);
static_assert(result.first - begin(input) == 3, "a lower bound position is 3.");
static_assert(result.second - begin(input) == 7, "a upper bound position is 7.");
static_assert(sprout::all_of_equal(result.first, result.second. 5), "all of result range is equal to 5.");
Complexity
========================================
| At most ``2 * log2(last - first) + O(1)`` comparisons.
| Recursive function invocations in *O(logN)* (logarithmic) depth.
Header
========================================
| ``sprout/algorithm/equal_range.hpp``
| Convenience header: ``sprout/algorithm.hpp``

View file

@ -33,6 +33,10 @@ Sprout.Algorithm
is_decreasing
is_strictly_increasing
is_strictly_decreasing
lower_bound
upper_bound
equal_range
binary_search
.. _sprout-algorithm-non_modifying:
*******************************************************************************

View file

@ -0,0 +1,52 @@
.. _sprout-algorithm-lower_bound:
###############################################################################
lower_bound
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<typename ForwardIterator, typename T>
inline SPROUT_CONSTEXPR ForwardIterator
lower_bound(ForwardIterator first, ForwardIterator last, T const& value);
template<typename ForwardIterator, typename T, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator
lower_bound(ForwardIterator first, ForwardIterator last, T const& value, Compare comp);
Requires
========================================
| The elements e of [first,last) shall be partitioned with respect to the expression ``e < value`` or ``comp(e, value)``.
Returns
========================================
| The furthermost iterator i in the range [first,last] such that for any iterator j in the range [first,i) the following corresponding conditions hold: ``*j < value`` or ``comp(*j, value)``.
Examples
========================================
.. sourcecode:: c++
#include <sprout/algorithm/lower_bound.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::lower_bound(begin(input), end(input), 5);
static_assert(result - begin(input) == 3, "a lower bound position is 3.");
Complexity
========================================
| At most ``log2(last - first) + O(1)`` comparisons.
| Recursive function invocations in *O(logN)* (logarithmic) depth.
Header
========================================
| ``sprout/algorithm/lower_bound.hpp``
| Convenience header: ``sprout/algorithm.hpp``

View file

@ -0,0 +1,52 @@
.. _sprout-algorithm-upper_bound:
###############################################################################
upper_bound
###############################################################################
Interface
========================================
.. sourcecode:: c++
template<typename ForwardIterator, typename T>
inline SPROUT_CONSTEXPR ForwardIterator
upper_bound(ForwardIterator first, ForwardIterator last, T const& value);
template<typename ForwardIterator, typename T, typename Compare>
inline SPROUT_CONSTEXPR ForwardIterator
upper_bound(ForwardIterator first, ForwardIterator last, T const& value, Compare comp);
Requires
========================================
| The elements e of [first,last) shall be partitioned with respect to the expression ``!(value < e)`` or ``!comp(value, e)``.
Returns
========================================
| The furthermost iterator i in the range [first,last] such that for any iterator j in the range [first,i) the following corresponding conditions hold: ``!(value < *j)`` or ``!comp(value, *j)``.
Examples
========================================
.. sourcecode:: c++
#include <sprout/algorithm/upper_bound.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::upper_bound(begin(input), end(input), 5);
static_assert(result - begin(input) == 7, "a upper bound position is 7.");
Complexity
========================================
| At most ``log2(last - first) + O(1)`` comparisons.
| Recursive function invocations in *O(logN)* (logarithmic) depth.
Header
========================================
| ``sprout/algorithm/upper_bound.hpp``
| Convenience header: ``sprout/algorithm.hpp``