forked from cplusplus/fundamentals-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
algorithms.html
115 lines (98 loc) · 5.77 KB
/
algorithms.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<cxx-clause id="algorithms">
<h1>Algorithms library</h1>
<cxx-section id="header.algorithm.synop">
<h1>Header <code><experimental/algorithm></code> synopsis</h1>
<pre><code>#include <algorithm>
namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
<cxx-ref insynopsis="" to="alg.search"></cxx-ref>
template<class ForwardIterator, class Searcher>
ForwardIterator search(ForwardIterator first, ForwardIterator last,
const Searcher& searcher);
<cxx-ref insynopsis="" to="alg.random.sample"></cxx-ref>
template<class PopulationIterator, class SampleIterator, class Distance>
SampleIterator sample(PopulationIterator first, PopulationIterator last,
SampleIterator out, Distance n);
template<class PopulationIterator, class SampleIterator,
class Distance, class UniformRandomNumberGenerator>
SampleIterator sample(PopulationIterator first, PopulationIterator last,
SampleIterator out, Distance n,
UniformRandomNumberGenerator&& g);
<cxx-ref insynopsis="" to="alg.random.shuffle"></cxx-ref>
template<class RandomAccessIterator>
void shuffle(RandomAccessIterator first, RandomAccessIterator last);
} // namespace fundamentals_v2
} // namespace experimental
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="alg.search">
<h1>Search</h1>
<cxx-function>
<cxx-signature>template<class ForwardIterator, class Searcher>
ForwardIterator search(ForwardIterator first, ForwardIterator last,
const Searcher& searcher);</cxx-signature>
<cxx-effects>Equivalent to <code>return searcher(first, last);</code></cxx-effects>
<cxx-remarks><code>Searcher</code> need not meet the <code>CopyConstructible</code> requirements.</cxx-remarks>
</cxx-function>
</cxx-section>
<cxx-section id="alg.random.sample">
<h1>Sampling</h1>
<cxx-function>
<cxx-signature class="formatted">template<class PopulationIterator, class SampleIterator, class Distance>
SampleIterator sample(PopulationIterator first, PopulationIterator last,
SampleIterator out, Distance n);
template<class PopulationIterator, class SampleIterator,
class Distance, class UniformRandomNumberGenerator>
SampleIterator sample(PopulationIterator first, PopulationIterator last,
SampleIterator out, Distance n,
UniformRandomNumberGenerator&& g);</cxx-signature>
<cxx-requires>
<ul>
<li><code>PopulationIterator</code> shall meet the requirements of an <code>InputIterator</code> type.</li>
<li><code>SampleIterator</code> shall meet the requirements of an <code>OutputIterator</code> type.</li>
<li><code>SampleIterator</code> shall meet the additional requirements of a <code>RandomAccessIterator</code> type
unless <code>PopulationIterator</code> meets the additional requirements of a <code>ForwardIterator</code> type.</li>
<li><code>PopulationIterator</code>'s value type shall be writable to <code>out</code>.</li>
<li><code>Distance</code> shall be an integer type.</li>
<li><code>UniformRandomNumberGenerator</code> shall meet the requirements of a uniform random number generator type (<cxx-ref in="cxx" to="rand.req.urng"></cxx-ref>)
whose return type is convertible to <code>Distance</code>.</li>
<li><code>out</code> shall not be in the range <cxx-range begin="first" end="last"></cxx-range>.</li>
</ul>
</cxx-requires>
<cxx-effects>Copies <code>min(last−first, n)</code> elements (the <dfn>sample</dfn>)
from <cxx-range begin="first" end="last"></cxx-range> (the <dfn>population</dfn>) to <code>out</code>
such that each possible sample has equal probability of appearance.
<cxx-note>Algorithms that obtain such effects include <cxx-term>selection sampling</cxx-term> and <cxx-term>reservoir sampling</cxx-term>.</cxx-note></cxx-effects>
<cxx-returns>The end of the resulting sample range.</cxx-returns>
<cxx-complexity>O(<code>last - first</code>).</cxx-complexity>
<cxx-remarks>
<ul>
<li>Stable if and only if <code>PopulationIterator</code> meets the
requirements of a <code>ForwardIterator</code> type.</li>
<li>If <code>g</code> is not given in the argument list, it denotes
the per-thread engine (<cxx-ref to="rand.util.randint"></cxx-ref>).
To the extent that the implementation of this function makes use of
random numbers, the object <code>g</code> shall serve as the
implementation’s source of randomness.</li>
</ul>
</cxx-remarks>
</cxx-function>
</cxx-section>
<cxx-section id="alg.random.shuffle">
<h1>Shuffle</h1>
<cxx-function>
<cxx-signature>template<class RandomAccessIterator>
void shuffle(RandomAccessIterator first, RandomAccessIterator last);</cxx-signature>
<cxx-effects>Permutes the elements in the range <code>[first,last)</code>
such that each possible permutation of those elements has equal
probability of appearance.</cxx-effects>
<cxx-requires><code>RandomAccessIterator</code> shall satisfy the
requirements of <code>ValueSwappable</code> (<cxx-ref in="cxx" to="swappable.requirements"></cxx-ref>).</cxx-requires>
<cxx-complexity>Exactly <code>(last - first) - 1</code> swaps.</cxx-complexity>
<cxx-remarks>To the extent that the implementation of this function
makes use of random numbers, the per-thread engine (<cxx-ref to="rand.util.randint"></cxx-ref>)
shall serve as the implementation's source of randomness.</cxx-remarks>
</cxx-function>
</cxx-section>
</cxx-clause>