• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Function template reverse_string_sort</title>
5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../index.html" title="Boost.Sort">
8<link rel="up" href="../../../header/boost/sort/spreadsort/string_sort_hpp.html" title="Header &lt;boost/sort/spreadsort/string_sort.hpp&gt;">
9<link rel="prev" href="reverse__idm45878543470704.html" title="Function template reverse_string_sort">
10<link rel="next" href="../../../sort/single_thread/pdqsort.html" title="2.2.- pdqsort">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="reverse__idm45878543470704.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../header/boost/sort/spreadsort/string_sort_hpp.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../../sort/single_thread/pdqsort.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="refentry">
26<a name="boost.sort.spreadsort.reverse__idm45878543439168"></a><div class="titlepage"></div>
27<div class="refnamediv">
28<h2><span class="refentrytitle">Function template reverse_string_sort</span></h2>
29<p>boost::sort::spreadsort::reverse_string_sort — Reverse String sort algorithm using range. </p>
30</div>
31<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
32<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../../header/boost/sort/spreadsort/string_sort_hpp.html" title="Header &lt;boost/sort/spreadsort/string_sort.hpp&gt;">boost/sort/spreadsort/string_sort.hpp</a>&gt;
33
34</span>
35<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Range<span class="special">,</span> <span class="keyword">typename</span> Get_char<span class="special">,</span> <span class="keyword">typename</span> Get_length<span class="special">,</span>
36         <span class="keyword">typename</span> Compare<span class="special">&gt;</span>
37  <span class="keyword">void</span> <span class="identifier">reverse_string_sort</span><span class="special">(</span><span class="identifier">Range</span> <span class="special">&amp;</span> range<span class="special">,</span> <span class="identifier">Get_char</span> get_character<span class="special">,</span>
38                           <span class="identifier">Get_length</span> length<span class="special">,</span> <span class="identifier">Compare</span> comp<span class="special">)</span><span class="special">;</span></pre></div>
39<div class="refsect1">
40<a name="idm45477844058224"></a><h2>Description</h2>
41<p>(All variants fall back to <code class="computeroutput">boost::sort::pdqsort</code> if the data size is too small, &lt; <code class="computeroutput">detail::min_sort_size</code>).</p>
42<p><code class="computeroutput">string_sort</code> is a fast templated in-place hybrid radix/comparison algorithm, which in testing tends to be roughly 50% to 2X faster than <code class="computeroutput">std::sort</code> for large tests (&gt;=100kB).<br>
43</p>
44<p><b> </b>Worst-case performance is <span class="emphasis"><em> O(N * (lg(range)/s + s)) </em></span>, so <code class="computeroutput">string_sort</code> is asymptotically faster than pure comparison-based algorithms. <br>
45<br>
46Some performance plots of runtime vs. n and log(range) are provided:<br>
47<a href="../../../../../doc/graph/windows_string_sort.htm" target="_top">windows_string_sort</a><br>
48<a href="../../../../../doc/graph/osx_string_sort.htm" target="_top">osx_string_sort</a></p>
49<p>
50
51
52
53
54
55</p>
56<div class="warning"><table border="0" summary="Warning">
57<tr>
58<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
59<th align="left">Warning</th>
60</tr>
61<tr><td align="left" valign="top"><p>Throwing an exception may cause data loss. This will also throw if a small vector resize throws, in which case there will be no data loss. </p></td></tr>
62</table></div>
63<p>
64</p>
65<div class="warning"><table border="0" summary="Warning">
66<tr>
67<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
68<th align="left">Warning</th>
69</tr>
70<tr><td align="left" valign="top"><p>Invalid arguments cause undefined behaviour. </p></td></tr>
71</table></div>
72<p>
73</p>
74<div class="note"><table border="0" summary="Note">
75<tr>
76<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
77<th align="left">Note</th>
78</tr>
79<tr><td align="left" valign="top"><p><code class="computeroutput">spreadsort</code> function provides a wrapper that calls the fastest sorting algorithm available for a data type, enabling faster generic-programming.</p></td></tr>
80</table></div>
81<p>
82</p>
83<p>The lesser of <span class="emphasis"><em> O(N*log(N)) </em></span> comparisons and <span class="emphasis"><em> O(N*log(K/S + S)) </em></span>operations worst-case, where: </p>
84<p>
85
86</p>
87<p>* N is <code class="computeroutput">last</code> - <code class="computeroutput">first</code>, </p>
88<p>
89
90</p>
91<p>* K is the log of the range in bits (32 for 32-bit integers using their full range), </p>
92<p>
93
94</p>
95<p>* S is a constant called max_splits, defaulting to 11 (except for strings where it is the log of the character size). </p>
96<p>
97
98</p>
99<div class="variablelist"><table border="0" class="variablelist compact">
100<colgroup>
101<col align="left" valign="top">
102<col>
103</colgroup>
104<tbody>
105<tr>
106<td><p><span class="term">Parameters:</span></p></td>
107<td><div class="variablelist"><table border="0" class="variablelist compact">
108<colgroup>
109<col align="left" valign="top">
110<col>
111</colgroup>
112<tbody>
113<tr>
114<td><p><span class="term"><code class="computeroutput">comp</code></span></p></td>
115<td><p>A binary functor that returns whether the first element passed to it should go before the second in order.</p></td>
116</tr>
117<tr>
118<td><p><span class="term"><code class="computeroutput">get_character</code></span></p></td>
119<td><p>Bracket functor equivalent to <code class="computeroutput">operator</code>[], taking a number corresponding to the character offset. </p></td>
120</tr>
121<tr>
122<td><p><span class="term"><code class="computeroutput">length</code></span></p></td>
123<td><p>Functor to get the length of the string in characters. </p></td>
124</tr>
125<tr>
126<td><p><span class="term"><code class="computeroutput">range</code></span></p></td>
127<td><p>Range [first, last) for sorting. </p></td>
128</tr>
129</tbody>
130</table></div></td>
131</tr>
132<tr>
133<td><p><span class="term">Requires:</span></p></td>
134<td><p>[<code class="computeroutput">first</code>, <code class="computeroutput">last</code>) is a valid range. </p></td>
135</tr>
136<tr>
137<td><p><span class="term">Postconditions:</span></p></td>
138<td><p>The elements in the range [<code class="computeroutput">first</code>, <code class="computeroutput">last</code>) are sorted in ascending order.</p></td>
139</tr>
140<tr>
141<td><p><span class="term">Returns:</span></p></td>
142<td><p><code class="computeroutput">void</code>.</p></td>
143</tr>
144<tr>
145<td><p><span class="term">Throws:</span></p></td>
146<td>std::exception Propagates exceptions if any of the element comparisons, the element swaps (or moves), the right shift, subtraction of right-shifted elements, functors, or any operations on iterators throw.</td>
147</tr>
148</tbody>
149</table></div>
150</div>
151</div>
152<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
153<td align="left"></td>
154<td align="right"><div class="copyright-footer">Copyright © 2014-2017 Steven
155      Ross, Francisco Tapia, Orson Peters<p>
156        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
157        Software License, Version 1.0</a>.
158      </p>
159</div></td>
160</tr></table>
161<hr>
162<div class="spirit-nav">
163<a accesskey="p" href="reverse__idm45878543470704.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../header/boost/sort/spreadsort/string_sort_hpp.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../../sort/single_thread/pdqsort.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
164</div>
165</body>
166</html>
167