root/doc/html/classitpp_1_1Sort.html @ 354

Revision 353, 20.3 kB (checked in by smidl, 15 years ago)

doc

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3<title>mixpp: itpp::Sort&lt; T &gt; Class Template Reference</title>
4<link href="tabs.css" rel="stylesheet" type="text/css">
5<link href="doxygen.css" rel="stylesheet" type="text/css">
6</head><body>
7<!-- Generated by Doxygen 1.5.8 -->
8<script type="text/javascript">
9<!--
10function changeDisplayState (e){
11  var num=this.id.replace(/[^[0-9]/g,'');
12  var button=this.firstChild;
13  var sectionDiv=document.getElementById('dynsection'+num);
14  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
15    sectionDiv.style.display='block';
16    button.src='open.gif';
17  }else{
18    sectionDiv.style.display='none';
19    button.src='closed.gif';
20  }
21}
22function initDynSections(){
23  var divs=document.getElementsByTagName('div');
24  var sectionCounter=1;
25  for(var i=0;i<divs.length-1;i++){
26    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
27      var header=divs[i];
28      var section=divs[i+1];
29      var button=header.firstChild;
30      if (button!='IMG'){
31        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
32        button=document.createElement('img');
33        divs[i].insertBefore(button,divs[i].firstChild);
34      }
35      header.style.cursor='pointer';
36      header.onclick=changeDisplayState;
37      header.id='dynheader'+sectionCounter;
38      button.src='closed.gif';
39      section.id='dynsection'+sectionCounter;
40      section.style.display='none';
41      section.style.marginLeft='14px';
42      sectionCounter++;
43    }
44  }
45}
46window.onload = initDynSections;
47-->
48</script>
49<div class="navigation" id="top">
50  <div class="tabs">
51    <ul>
52      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
53      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
54      <li><a href="modules.html"><span>Modules</span></a></li>
55      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
56      <li><a href="files.html"><span>Files</span></a></li>
57    </ul>
58  </div>
59  <div class="tabs">
60    <ul>
61      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
62      <li><a href="classes.html"><span>Class&nbsp;Index</span></a></li>
63      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
64      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
65    </ul>
66  </div>
67  <div class="navpath"><b>itpp</b>::<a class="el" href="classitpp_1_1Sort.html">Sort</a>
68  </div>
69</div>
70<div class="contents">
71<h1>itpp::Sort&lt; T &gt; Class Template Reference</h1><!-- doxytag: class="itpp::Sort" -->Class for sorting of vectors. 
72<a href="#_details">More...</a>
73<p>
74<code>#include &lt;<a class="el" href="sort_8h-source.html">sort.h</a>&gt;</code>
75<p>
76
77<p>
78<a href="classitpp_1_1Sort-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
79<tr><td></td></tr>
80<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
81<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="e89f0cdcd430af54b41520385b06c9b9"></a><!-- doxytag: member="itpp::Sort::Sort" ref="e89f0cdcd430af54b41520385b06c9b9" args="(SORTING_METHOD method=INTROSORT)" -->
82&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classitpp_1_1Sort.html#e89f0cdcd430af54b41520385b06c9b9">Sort</a> (SORTING_METHOD method=INTROSORT)</td></tr>
83
84<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Constructor that sets Intro <a class="el" href="classitpp_1_1Sort.html" title="Class for sorting of vectors.">Sort</a> method by default. <br></td></tr>
85<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="0fe6dbe275ae1eb38d34e0bea3604044"></a><!-- doxytag: member="itpp::Sort::set_method" ref="0fe6dbe275ae1eb38d34e0bea3604044" args="(SORTING_METHOD method)" -->
86void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classitpp_1_1Sort.html#0fe6dbe275ae1eb38d34e0bea3604044">set_method</a> (SORTING_METHOD method)</td></tr>
87
88<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Set sorting method. <br></td></tr>
89<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="17222b0f57479cf93632b0caabbe6abc"></a><!-- doxytag: member="itpp::Sort::get_method" ref="17222b0f57479cf93632b0caabbe6abc" args="() const " -->
90SORTING_METHOD&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classitpp_1_1Sort.html#17222b0f57479cf93632b0caabbe6abc">get_method</a> () const </td></tr>
91
92<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Get current sorting method. <br></td></tr>
93<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classitpp_1_1Sort.html#0ccff5c48c69b4680347935039a0d3f1">sort</a> (int low, int high, <a class="el" href="classitpp_1_1Vec.html">Vec</a>&lt; T &gt; &amp;data)</td></tr>
94
95<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sorting function of a subset of a vector <em>data</em><a href="#0ccff5c48c69b4680347935039a0d3f1"></a><br></td></tr>
96<tr><td class="memItemLeft" nowrap align="right" valign="top">ivec&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classitpp_1_1Sort.html#5eefe31327b1987cf9799562333ebccb">sort_index</a> (int low, int high, const <a class="el" href="classitpp_1_1Vec.html">Vec</a>&lt; T &gt; &amp;data)</td></tr>
97
98<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sorting function that returns a sorted index vector.  <a href="#5eefe31327b1987cf9799562333ebccb"></a><br></td></tr>
99<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classitpp_1_1Sort.html#5730b92e4812e1cd376619c16cda36d8">intro_sort</a> (int low, int high, int max_depth, <a class="el" href="classitpp_1_1Vec.html">Vec</a>&lt; T &gt; &amp;data)</td></tr>
100
101<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Introsort function of a subset of a vector <code>data</code><a href="#5730b92e4812e1cd376619c16cda36d8"></a><br></td></tr>
102<tr><td class="memItemLeft" nowrap align="right" valign="top">ivec&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classitpp_1_1Sort.html#b738462d713bcdb42d758e730819b499">intro_sort_index</a> (int low, int high, int max_depth, const <a class="el" href="classitpp_1_1Vec.html">Vec</a>&lt; T &gt; &amp;data)</td></tr>
103
104<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Introsort function, which returns a sorted index vector.  <a href="#b738462d713bcdb42d758e730819b499"></a><br></td></tr>
105</table>
106<hr><a name="_details"></a><h2>Detailed Description</h2>
107<h3>template&lt;class T&gt;<br>
108 class itpp::Sort&lt; T &gt;</h3>
109
110Class for sorting of vectors.
111<p>
112A class which takes a vector, and sorts its values descending. There are two types of sort: a normal sort (accessed via the <a class="el" href="classitpp_1_1Sort.html#0ccff5c48c69b4680347935039a0d3f1" title="Sorting function of a subset of a vector data.">Sort::sort()</a> function) which sorts the vector passed in the argument, and an index sort (accessed via the <a class="el" href="classitpp_1_1Sort.html#5eefe31327b1987cf9799562333ebccb" title="Sorting function that returns a sorted index vector.">Sort::sort_index()</a> function) which leaves the passed vector intact, but returns an index vector describing the sorted order.<p>
113The <a class="el" href="classitpp_1_1Sort.html" title="Class for sorting of vectors.">Sort</a> class has four sorting methods implemented:<ul>
114<li>Introsort [1,2]: It is a sorting algorithm developed by David Musser. I starts as a quicksort, but switches to a heapsort in cases where the recursion becomes too deep. Additionally, when sub vectors become smaller than 16 elements, it switches to an insertion sort. Introsort has a worst-case of <img class="formulaInl" alt="$\Theta(n\log n)$" src="form_186.png"> comparisons, bu has the efficiency of the quick sort algorithm in cases where the data is well conditioned for quicksort.</li><li>Quicksort [3]: It is a comparison sorting algorithm that has an average complexity of <img class="formulaInl" alt="$\Theta(n\log n)$" src="form_186.png"> comparisons. For most data sets, the quicksort will be significantly more efficient than this average. However for data sets not well suited to it, quicksort may require as many as <img class="formulaInl" alt="$\Theta(n^2)$" src="form_187.png"> comparisons. Example of such ill-suited data sets are those which are nearly in order, and data sets with multiple elements of the same value.</li><li>Heapsort [4]: It is a comparison sorting algorithm. While it is usually seen to be slower than quicksort routines, its worst-case requires only <img class="formulaInl" alt="$\Theta(n\log n)$" src="form_186.png"> comparisons. This makes it an ideal quicksort replacement for data sets that that are ill-conditioned for quicksorting.</li><li>Insertion sort [5]: An insertion sort is a simple comparison sort, which is widely considered to be one of the most efficient algorithms for very small data sets (10-20 elements). <a href="http://en.wikipedia.org/wiki/Insertion_sort">http://en.wikipedia.org/wiki/Insertion_sort</a></li></ul>
115<p>
116References:<ul>
117<li>[1] <a href="http://en.wikipedia.org/wiki/Introsort">http://en.wikipedia.org/wiki/Introsort</a></li><li>[2] <a href="http://www.cs.rpi.edu/~musser/gp/introsort.ps">http://www.cs.rpi.edu/~musser/gp/introsort.ps</a></li><li>[3] <a href="http://en.wikipedia.org/wiki/Quicksort">http://en.wikipedia.org/wiki/Quicksort</a></li><li>[4] <a href="http://en.wikipedia.org/wiki/Heapsort">http://en.wikipedia.org/wiki/Heapsort</a></li><li>[5] <a href="http://en.wikipedia.org/wiki/Insertion_sort">http://en.wikipedia.org/wiki/Insertion_sort</a></li></ul>
118<p>
119<dl class="author" compact><dt><b>Author:</b></dt><dd>Tony Ottosson (Quicksort), Mark Dobossy (Introsort, Heapsort and Insertion <a class="el" href="classitpp_1_1Sort.html" title="Class for sorting of vectors.">Sort</a>) and Adam Piatyszek (<a class="el" href="classitpp_1_1Sort.html" title="Class for sorting of vectors.">Sort</a> class design, code clean-up) </dd></dl>
120<hr><h2>Member Function Documentation</h2>
121<a class="anchor" name="5730b92e4812e1cd376619c16cda36d8"></a><!-- doxytag: member="itpp::Sort::intro_sort" ref="5730b92e4812e1cd376619c16cda36d8" args="(int low, int high, int max_depth, Vec&lt; T &gt; &amp;data)" -->
122<div class="memitem">
123<div class="memproto">
124<div class="memtemplate">
125template&lt;class T &gt; </div>
126      <table class="memname">
127        <tr>
128          <td class="memname">void <a class="el" href="classitpp_1_1Sort.html">itpp::Sort</a>&lt; T &gt;::intro_sort           </td>
129          <td>(</td>
130          <td class="paramtype">int&nbsp;</td>
131          <td class="paramname"> <em>low</em>, </td>
132        </tr>
133        <tr>
134          <td class="paramkey"></td>
135          <td></td>
136          <td class="paramtype">int&nbsp;</td>
137          <td class="paramname"> <em>high</em>, </td>
138        </tr>
139        <tr>
140          <td class="paramkey"></td>
141          <td></td>
142          <td class="paramtype">int&nbsp;</td>
143          <td class="paramname"> <em>max_depth</em>, </td>
144        </tr>
145        <tr>
146          <td class="paramkey"></td>
147          <td></td>
148          <td class="paramtype"><a class="el" href="classitpp_1_1Vec.html">Vec</a>&lt; T &gt; &amp;&nbsp;</td>
149          <td class="paramname"> <em>data</em></td><td>&nbsp;</td>
150        </tr>
151        <tr>
152          <td></td>
153          <td>)</td>
154          <td></td><td></td><td><code> [inline]</code></td>
155        </tr>
156      </table>
157</div>
158<div class="memdoc">
159
160<p>
161Introsort function of a subset of a vector <code>data</code>.
162<p>
163<dl compact><dt><b>Parameters:</b></dt><dd>
164  <table border="0" cellspacing="2" cellpadding="0">
165    <tr><td valign="top"></td><td valign="top"><em>low</em>&nbsp;</td><td>Start index of a subvector to be sorted </td></tr>
166    <tr><td valign="top"></td><td valign="top"><em>high</em>&nbsp;</td><td>End index of a subvector to be sorted </td></tr>
167    <tr><td valign="top"></td><td valign="top"><em>max_depth</em>&nbsp;</td><td>Maximum recursion depth before switching to heap sort recommended value: log2 of the length of the data vector </td></tr>
168    <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>Data vector, in which a part of it is to be sorted</td></tr>
169  </table>
170</dl>
171<dl class="note" compact><dt><b>Note:</b></dt><dd>An introsort is not a stable sort (i.e. it may not maintain the relative order of elements with equal value.) <p>
172This function uses recurrence. </dd></dl>
173
174<p>References <a class="el" href="vec_8h-source.html#l00505">itpp::Vec&lt; Num_T &gt;::_data()</a>, <a class="el" href="itassert_8h-source.html#l00094">it_assert</a>, and <a class="el" href="vec_8h-source.html#l00277">itpp::Vec&lt; Num_T &gt;::size()</a>.</p>
175
176</div>
177</div><p>
178<a class="anchor" name="b738462d713bcdb42d758e730819b499"></a><!-- doxytag: member="itpp::Sort::intro_sort_index" ref="b738462d713bcdb42d758e730819b499" args="(int low, int high, int max_depth, const Vec&lt; T &gt; &amp;data)" -->
179<div class="memitem">
180<div class="memproto">
181<div class="memtemplate">
182template&lt;class T &gt; </div>
183      <table class="memname">
184        <tr>
185          <td class="memname">ivec <a class="el" href="classitpp_1_1Sort.html">itpp::Sort</a>&lt; T &gt;::intro_sort_index           </td>
186          <td>(</td>
187          <td class="paramtype">int&nbsp;</td>
188          <td class="paramname"> <em>low</em>, </td>
189        </tr>
190        <tr>
191          <td class="paramkey"></td>
192          <td></td>
193          <td class="paramtype">int&nbsp;</td>
194          <td class="paramname"> <em>high</em>, </td>
195        </tr>
196        <tr>
197          <td class="paramkey"></td>
198          <td></td>
199          <td class="paramtype">int&nbsp;</td>
200          <td class="paramname"> <em>max_depth</em>, </td>
201        </tr>
202        <tr>
203          <td class="paramkey"></td>
204          <td></td>
205          <td class="paramtype">const <a class="el" href="classitpp_1_1Vec.html">Vec</a>&lt; T &gt; &amp;&nbsp;</td>
206          <td class="paramname"> <em>data</em></td><td>&nbsp;</td>
207        </tr>
208        <tr>
209          <td></td>
210          <td>)</td>
211          <td></td><td></td><td><code> [inline]</code></td>
212        </tr>
213      </table>
214</div>
215<div class="memdoc">
216
217<p>
218Introsort function, which returns a sorted index vector.
219<p>
220<dl compact><dt><b>Parameters:</b></dt><dd>
221  <table border="0" cellspacing="2" cellpadding="0">
222    <tr><td valign="top"></td><td valign="top"><em>low</em>&nbsp;</td><td>Start index of a subvector to be sorted </td></tr>
223    <tr><td valign="top"></td><td valign="top"><em>high</em>&nbsp;</td><td>End index of a subvector to be sorted </td></tr>
224    <tr><td valign="top"></td><td valign="top"><em>max_depth</em>&nbsp;</td><td>Maximum recursion depth before switching to heap sort recommended value: log2 of the length of the data vector </td></tr>
225    <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>Data vector, in which a part of it is to be sorted</td></tr>
226  </table>
227</dl>
228<dl class="note" compact><dt><b>Note:</b></dt><dd>An Introsort is not a stable sort (i.e. it may not maintain the relative order of elements with equal value.) <p>
229This function uses recurrence. </dd></dl>
230
231<p>References <a class="el" href="vec_8h-source.html#l00505">itpp::Vec&lt; Num_T &gt;::_data()</a>, <a class="el" href="itassert_8h-source.html#l00094">it_assert</a>, and <a class="el" href="vec_8h-source.html#l00277">itpp::Vec&lt; Num_T &gt;::size()</a>.</p>
232
233</div>
234</div><p>
235<a class="anchor" name="0ccff5c48c69b4680347935039a0d3f1"></a><!-- doxytag: member="itpp::Sort::sort" ref="0ccff5c48c69b4680347935039a0d3f1" args="(int low, int high, Vec&lt; T &gt; &amp;data)" -->
236<div class="memitem">
237<div class="memproto">
238<div class="memtemplate">
239template&lt;class T &gt; </div>
240      <table class="memname">
241        <tr>
242          <td class="memname">void <a class="el" href="classitpp_1_1Sort.html">itpp::Sort</a>&lt; T &gt;::sort           </td>
243          <td>(</td>
244          <td class="paramtype">int&nbsp;</td>
245          <td class="paramname"> <em>low</em>, </td>
246        </tr>
247        <tr>
248          <td class="paramkey"></td>
249          <td></td>
250          <td class="paramtype">int&nbsp;</td>
251          <td class="paramname"> <em>high</em>, </td>
252        </tr>
253        <tr>
254          <td class="paramkey"></td>
255          <td></td>
256          <td class="paramtype"><a class="el" href="classitpp_1_1Vec.html">Vec</a>&lt; T &gt; &amp;&nbsp;</td>
257          <td class="paramname"> <em>data</em></td><td>&nbsp;</td>
258        </tr>
259        <tr>
260          <td></td>
261          <td>)</td>
262          <td></td><td></td><td><code> [inline]</code></td>
263        </tr>
264      </table>
265</div>
266<div class="memdoc">
267
268<p>
269Sorting function of a subset of a vector <em>data</em>.
270<p>
271<dl compact><dt><b>Parameters:</b></dt><dd>
272  <table border="0" cellspacing="2" cellpadding="0">
273    <tr><td valign="top"></td><td valign="top"><em>low</em>&nbsp;</td><td>Start index of a subvector to be sorted </td></tr>
274    <tr><td valign="top"></td><td valign="top"><em>high</em>&nbsp;</td><td>End index of a subvector to be sorted </td></tr>
275    <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>Data vector, in which a part of it is to be sorted </td></tr>
276  </table>
277</dl>
278
279<p>References <a class="el" href="vec_8h-source.html#l00505">itpp::Vec&lt; Num_T &gt;::_data()</a>, <a class="el" href="itassert_8h-source.html#l00094">it_assert</a>, <a class="el" href="itassert_8h-source.html#l00126">it_error</a>, <a class="el" href="log__exp_8h-source.html#l00303">itpp::levels2bits()</a>, and <a class="el" href="vec_8h-source.html#l00277">itpp::Vec&lt; Num_T &gt;::size()</a>.</p>
280
281<p>Referenced by <a class="el" href="sort_8h-source.html#l00187">itpp::Vec&lt; Num_T &gt;::sort()</a>.</p>
282
283</div>
284</div><p>
285<a class="anchor" name="5eefe31327b1987cf9799562333ebccb"></a><!-- doxytag: member="itpp::Sort::sort_index" ref="5eefe31327b1987cf9799562333ebccb" args="(int low, int high, const Vec&lt; T &gt; &amp;data)" -->
286<div class="memitem">
287<div class="memproto">
288<div class="memtemplate">
289template&lt;class T &gt; </div>
290      <table class="memname">
291        <tr>
292          <td class="memname">ivec <a class="el" href="classitpp_1_1Sort.html">itpp::Sort</a>&lt; T &gt;::sort_index           </td>
293          <td>(</td>
294          <td class="paramtype">int&nbsp;</td>
295          <td class="paramname"> <em>low</em>, </td>
296        </tr>
297        <tr>
298          <td class="paramkey"></td>
299          <td></td>
300          <td class="paramtype">int&nbsp;</td>
301          <td class="paramname"> <em>high</em>, </td>
302        </tr>
303        <tr>
304          <td class="paramkey"></td>
305          <td></td>
306          <td class="paramtype">const <a class="el" href="classitpp_1_1Vec.html">Vec</a>&lt; T &gt; &amp;&nbsp;</td>
307          <td class="paramname"> <em>data</em></td><td>&nbsp;</td>
308        </tr>
309        <tr>
310          <td></td>
311          <td>)</td>
312          <td></td><td></td><td><code> [inline]</code></td>
313        </tr>
314      </table>
315</div>
316<div class="memdoc">
317
318<p>
319Sorting function that returns a sorted index vector.
320<p>
321<dl compact><dt><b>Parameters:</b></dt><dd>
322  <table border="0" cellspacing="2" cellpadding="0">
323    <tr><td valign="top"></td><td valign="top"><em>low</em>&nbsp;</td><td>Start index of a subvector to be sorted </td></tr>
324    <tr><td valign="top"></td><td valign="top"><em>high</em>&nbsp;</td><td>End index of a subvector to be sorted </td></tr>
325    <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>Data vector, in which a part of it is to be sorted </td></tr>
326  </table>
327</dl>
328
329<p>References <a class="el" href="vec_8h-source.html#l00505">itpp::Vec&lt; Num_T &gt;::_data()</a>, <a class="el" href="itassert_8h-source.html#l00094">it_assert</a>, <a class="el" href="itassert_8h-source.html#l00126">it_error</a>, <a class="el" href="log__exp_8h-source.html#l00303">itpp::levels2bits()</a>, and <a class="el" href="vec_8h-source.html#l00277">itpp::Vec&lt; Num_T &gt;::size()</a>.</p>
330
331<p>Referenced by <a class="el" href="sort_8h-source.html#l00203">itpp::Vec&lt; Num_T &gt;::sort_index()</a>.</p>
332
333</div>
334</div><p>
335<hr>The documentation for this class was generated from the following file:<ul>
336<li><a class="el" href="sort_8h-source.html">sort.h</a></ul>
337</div>
338<hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:19 2009 for mixpp by&nbsp;
339<a href="http://www.doxygen.org/index.html">
340<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
341</body>
342</html>
Note: See TracBrowser for help on using the browser.