|
|
|
|
@ -3886,10 +3886,10 @@ class="pplb7t-x-x-120">_hsort — Sorting by the Heapsort algorithm</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<pre class="verbatim" id="verbatim-60">
|
|
|
|
|
call psb_isort(x,ix,dir,flag)
|
|
|
|
|
call psb_msort(x,ix,dir,flag)
|
|
|
|
|
call psb_qsort(x,ix,dir,flag)
|
|
|
|
|
call psb_hsort(x,ix,dir,flag)
|
|
|
|
|
call psb_isort(x,ix,dir,flag,reord)
|
|
|
|
|
call psb_msort(x,ix,dir,flag,reord)
|
|
|
|
|
call psb_qsort(x,ix,dir,flag,reord)
|
|
|
|
|
call psb_hsort(x,ix,dir,flag,reord)
|
|
|
|
|
</pre>
|
|
|
|
|
<!--l. 1798--><p class="nopar" >
|
|
|
|
|
<!--l. 1800--><p class="indent" > These serial routines sort a sequence <span
|
|
|
|
|
@ -3925,23 +3925,30 @@ class="description">
|
|
|
|
|
<!--l. 1810--><p class="noindent" >A vector of indices.<br
|
|
|
|
|
class="newline" />Type:<span
|
|
|
|
|
class="pplb7t-">optional</span>.<br
|
|
|
|
|
class="newline" />Specified as: an integer array of (at least) the same size as <span
|
|
|
|
|
class="zplmr7m-">X</span>.
|
|
|
|
|
class="newline" />Specified as: an integer array of (at least) the same size as <span
|
|
|
|
|
class="zplmr7m-">X</span>. This
|
|
|
|
|
argument is required when <span
|
|
|
|
|
class="zplmr7m-">reord </span><span
|
|
|
|
|
class="zplmr7t-">= </span><span
|
|
|
|
|
class="zplmr7m-">psb</span>_<span
|
|
|
|
|
class="zplmr7m-">sort</span>_<span
|
|
|
|
|
class="zplmr7m-">noreord</span>_<span
|
|
|
|
|
class="zplmr7m-">x</span>_.
|
|
|
|
|
</dd><dt class="description">
|
|
|
|
|
<!--l. 1813--><p class="noindent" >
|
|
|
|
|
<!--l. 1814--><p class="noindent" >
|
|
|
|
|
<span
|
|
|
|
|
class="pplb7t-">dir</span> </dt><dd
|
|
|
|
|
class="description">
|
|
|
|
|
<!--l. 1813--><p class="noindent" >The desired ordering.<br
|
|
|
|
|
<!--l. 1814--><p class="noindent" >The desired ordering.<br
|
|
|
|
|
class="newline" />Type:<span
|
|
|
|
|
class="pplb7t-">optional</span>.<br
|
|
|
|
|
class="newline" />Specified as: an integer value:
|
|
|
|
|
<dl class="description"><dt class="description">
|
|
|
|
|
<!--l. 1816--><p class="noindent" >
|
|
|
|
|
<!--l. 1817--><p class="noindent" >
|
|
|
|
|
<span
|
|
|
|
|
class="pplb7t-">Integer and real data:</span> </dt><dd
|
|
|
|
|
class="description">
|
|
|
|
|
<!--l. 1816--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
<!--l. 1817--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_sort_up_</span></span></span>, <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_sort_down_</span></span></span>, <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_asort_up_</span></span></span>,
|
|
|
|
|
@ -3952,11 +3959,11 @@ class="cmtt-10">psb_sort_up_</span></span></span>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</dd><dt class="description">
|
|
|
|
|
<!--l. 1819--><p class="noindent" >
|
|
|
|
|
<!--l. 1820--><p class="noindent" >
|
|
|
|
|
<span
|
|
|
|
|
class="pplb7t-">Complex data:</span> </dt><dd
|
|
|
|
|
class="description">
|
|
|
|
|
<!--l. 1819--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
<!--l. 1820--><p class="noindent" ><span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_lsort_up_</span></span></span>, <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_lsort_down_</span></span></span>, <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_asort_up_</span></span></span>,
|
|
|
|
|
@ -3964,11 +3971,11 @@ class="cmtt-10">psb_asort_up_</span></span></span>,
|
|
|
|
|
class="cmtt-10">psb_asort_down_</span></span></span>; default <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_lsort_up_</span></span></span>.</dd></dl>
|
|
|
|
|
</dd><dt class="description">
|
|
|
|
|
<!--l. 1823--><p class="noindent" >
|
|
|
|
|
<!--l. 1824--><p class="noindent" >
|
|
|
|
|
<span
|
|
|
|
|
class="pplb7t-">flag</span> </dt><dd
|
|
|
|
|
class="description">
|
|
|
|
|
<!--l. 1823--><p class="noindent" >Whether to keep the original values in <span
|
|
|
|
|
<!--l. 1824--><p class="noindent" >Whether to keep the original values in <span
|
|
|
|
|
class="zplmr7m-">IX</span>.<br
|
|
|
|
|
class="newline" />Type:<span
|
|
|
|
|
class="pplb7t-">optional</span>.<br
|
|
|
|
|
@ -3977,54 +3984,73 @@ class="cmtt-10">psb_sort_ovw_idx_</span></span></span> or <span class="obeylines
|
|
|
|
|
class="cmtt-10">psb_sort_keep_idx_</span></span></span>;
|
|
|
|
|
default <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_sort_ovw_idx_</span></span></span>.
|
|
|
|
|
</dd><dt class="description">
|
|
|
|
|
<!--l. 1828--><p class="noindent" >
|
|
|
|
|
<span
|
|
|
|
|
class="pplb7t-">reord</span> </dt><dd
|
|
|
|
|
class="description">
|
|
|
|
|
<!--l. 1828--><p class="noindent" >Whether to reorder the input vector <span
|
|
|
|
|
class="zplmr7m-">x </span>or just return <span
|
|
|
|
|
class="zplmr7m-">IX </span>for further
|
|
|
|
|
usage.<br
|
|
|
|
|
class="newline" />Type:<span
|
|
|
|
|
class="pplb7t-">optional</span>.<br
|
|
|
|
|
class="newline" />Specified as: an integer value <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_sort_reord_x_</span></span></span> or <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_sort_noreord_x_</span></span></span>;
|
|
|
|
|
default <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">psb_sort_reord_x_</span></span></span>.
|
|
|
|
|
</dd></dl>
|
|
|
|
|
<!--l. 1830--><p class="indent" >
|
|
|
|
|
<!--l. 1836--><p class="indent" >
|
|
|
|
|
<dl class="description"><dt class="description">
|
|
|
|
|
<!--l. 1831--><p class="noindent" >
|
|
|
|
|
<!--l. 1837--><p class="noindent" >
|
|
|
|
|
<span
|
|
|
|
|
class="pplb7t-">On Return</span> </dt><dd
|
|
|
|
|
class="description">
|
|
|
|
|
<!--l. 1831--><p class="noindent" >
|
|
|
|
|
<!--l. 1837--><p class="noindent" >
|
|
|
|
|
</dd><dt class="description">
|
|
|
|
|
<!--l. 1832--><p class="noindent" >
|
|
|
|
|
<!--l. 1838--><p class="noindent" >
|
|
|
|
|
<span
|
|
|
|
|
class="pplb7t-">x</span> </dt><dd
|
|
|
|
|
class="description">
|
|
|
|
|
<!--l. 1832--><p class="noindent" >The sequence of values, in the chosen ordering.<br
|
|
|
|
|
<!--l. 1838--><p class="noindent" >The sequence of values; if <span class="obeylines-h"><span class="verb"><span
|
|
|
|
|
class="cmtt-10">reord=psb_sort_reord_x_</span></span></span> it will be in the
|
|
|
|
|
chosen ordering.<br
|
|
|
|
|
class="newline" />Type:<span
|
|
|
|
|
class="pplb7t-">required</span>.<br
|
|
|
|
|
class="newline" />Specified as: an integer, real or complex array of rank 1.
|
|
|
|
|
</dd><dt class="description">
|
|
|
|
|
<!--l. 1835--><p class="noindent" >
|
|
|
|
|
<!--l. 1842--><p class="noindent" >
|
|
|
|
|
<span
|
|
|
|
|
class="pplb7t-">ix</span> </dt><dd
|
|
|
|
|
class="description">
|
|
|
|
|
<!--l. 1835--><p class="noindent" >A vector of indices.<br
|
|
|
|
|
<!--l. 1842--><p class="noindent" >A vector of indices.<br
|
|
|
|
|
class="newline" />Type: <span
|
|
|
|
|
class="pplb7t-">Optional </span><br
|
|
|
|
|
class="newline" />An integer array of rank 1, whose entries are moved to the same position
|
|
|
|
|
as the corresponding entries in <span
|
|
|
|
|
class="zplmr7m-">x</span>.</dd></dl>
|
|
|
|
|
<!--l. 1841--><p class="noindent" ><span
|
|
|
|
|
class="newline" />An integer array of rank 1, whose <span
|
|
|
|
|
class="zplmr7m-">i</span>-th entry gives the position of the
|
|
|
|
|
(sorted) value of <span
|
|
|
|
|
class="zplmr7m-">x </span>in the original sequence.</dd></dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--l. 1848--><p class="noindent" ><span
|
|
|
|
|
class="pplb7t-x-x-120">Notes</span>
|
|
|
|
|
<ol class="enumerate1" >
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105002x1">
|
|
|
|
|
<!--l. 1843--><p class="noindent" >For integer or real data the sorting can be performed in the up/down
|
|
|
|
|
<!--l. 1850--><p class="noindent" >For integer or real data the sorting can be performed in the up/down
|
|
|
|
|
direction, on the natural or absolute values;
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105004x2">
|
|
|
|
|
<!--l. 1845--><p class="noindent" >For complex data the sorting can be done in a lexicographic order (i.e.:
|
|
|
|
|
<!--l. 1852--><p class="noindent" >For complex data the sorting can be done in a lexicographic order (i.e.:
|
|
|
|
|
sort on the real part with ties broken according to the imaginary part) or
|
|
|
|
|
on the absolute values;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105006x3">
|
|
|
|
|
<!--l. 1848--><p class="noindent" >The routines return the items in the chosen ordering; the output
|
|
|
|
|
<!--l. 1855--><p class="noindent" >The routines return the items in the chosen ordering; the output
|
|
|
|
|
difference is the handling of ties (i.e. items with an equal value) in the
|
|
|
|
|
original input. With the insertion-sort or merge-sort algorithms ties are
|
|
|
|
|
preserved in the same relative order as they had in the original sequence,
|
|
|
|
|
@ -4032,7 +4058,22 @@ class="pplb7t-x-x-120">Notes</span>
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105008x4">
|
|
|
|
|
<!--l. 1854--><p class="noindent" >If <span
|
|
|
|
|
<!--l. 1861--><p class="noindent" >If <span
|
|
|
|
|
class="zplmr7m-">reord </span><span
|
|
|
|
|
class="zplmr7t-">= </span><span
|
|
|
|
|
class="zplmr7m-">psb</span>_<span
|
|
|
|
|
class="zplmr7m-">sort</span>_<span
|
|
|
|
|
class="zplmr7m-">noreord</span>_<span
|
|
|
|
|
class="zplmr7m-">x</span>_, then the input sequence <span
|
|
|
|
|
class="zplmr7m-">x </span>is not reordered;
|
|
|
|
|
the output is given in <span
|
|
|
|
|
class="zplmr7m-">ix</span>. Calling without <span
|
|
|
|
|
class="zplmr7m-">ix </span>in this case is flagged as an
|
|
|
|
|
error;
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105010x5">
|
|
|
|
|
<!--l. 1864--><p class="noindent" >If <span
|
|
|
|
|
class="zplmr7m-">flag </span><span
|
|
|
|
|
class="zplmr7t-">= </span><span
|
|
|
|
|
class="zplmr7m-">psb</span>_<span
|
|
|
|
|
@ -4066,8 +4107,8 @@ class="zplmr7t-">) </span>occupied
|
|
|
|
|
in the original data sequence;
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105010x5">
|
|
|
|
|
<!--l. 1859--><p class="noindent" >If <span
|
|
|
|
|
class="enumerate" id="x12-105012x6">
|
|
|
|
|
<!--l. 1869--><p class="noindent" >If <span
|
|
|
|
|
class="zplmr7m-">flag </span><span
|
|
|
|
|
class="zplmr7t-">= </span><span
|
|
|
|
|
class="zplmr7m-">psb</span>_<span
|
|
|
|
|
@ -4079,8 +4120,11 @@ class="zplmr7m-">ix</span><span
|
|
|
|
|
class="zplmr7t-">(:) </span>have already been initialized by the user;
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105012x6">
|
|
|
|
|
<!--l. 1861--><p class="noindent" >Three sorting algorithms have a similar <span
|
|
|
|
|
class="enumerate" id="x12-105014x7">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--l. 1871--><p class="noindent" >Three sorting algorithms have a similar <span
|
|
|
|
|
class="zplmr7m-">O</span><span
|
|
|
|
|
class="zplmr7t-">(</span><span
|
|
|
|
|
class="zplmr7m-">n</span> log <span
|
|
|
|
|
@ -4096,8 +4140,8 @@ class="zplmr7t-">)</span>; of the other three,
|
|
|
|
|
However note that:
|
|
|
|
|
<ol class="enumerate2" >
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105014x1">
|
|
|
|
|
<!--l. 1866--><p class="noindent" >The the best case running time for insertion sort is <span
|
|
|
|
|
class="enumerate" id="x12-105016x1">
|
|
|
|
|
<!--l. 1876--><p class="noindent" >The the best case running time for insertion sort is <span
|
|
|
|
|
class="zplmr7t-">Ω(</span><span
|
|
|
|
|
class="zplmr7m-">n</span><span
|
|
|
|
|
class="zplmr7t-">) </span>while the
|
|
|
|
|
@ -4110,8 +4154,8 @@ class="zplmr7t-">)</span>; however for very short input
|
|
|
|
|
sequences this is likely to be the fastest method;
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105016x2">
|
|
|
|
|
<!--l. 1869--><p class="noindent" >The worst case running time
|
|
|
|
|
class="enumerate" id="x12-105018x2">
|
|
|
|
|
<!--l. 1879--><p class="noindent" >The worst case running time
|
|
|
|
|
for quicksort is <span
|
|
|
|
|
class="zplmr7m-">O</span><span
|
|
|
|
|
class="zplmr7t-">(</span><span
|
|
|
|
|
@ -4122,21 +4166,18 @@ class="zplmr7t-">)</span>; the algorithm implemented here follows the
|
|
|
|
|
apply;
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105018x3">
|
|
|
|
|
<!--l. 1872--><p class="noindent" >The worst case running time for merge-sort and heap-sort is
|
|
|
|
|
class="enumerate" id="x12-105020x3">
|
|
|
|
|
<!--l. 1882--><p class="noindent" >The worst case running time for merge-sort and heap-sort is
|
|
|
|
|
<span
|
|
|
|
|
class="zplmr7m-">O</span><span
|
|
|
|
|
class="zplmr7t-">(</span><span
|
|
|
|
|
class="zplmr7m-">n</span> log <span
|
|
|
|
|
class="zplmr7m-">n</span><span
|
|
|
|
|
class="zplmr7t-">) </span>as the average case;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
<li
|
|
|
|
|
class="enumerate" id="x12-105020x4">
|
|
|
|
|
<!--l. 1874--><p class="noindent" >The merge-sort algorithm is implemented to take advantage of
|
|
|
|
|
class="enumerate" id="x12-105022x4">
|
|
|
|
|
<!--l. 1884--><p class="noindent" >The merge-sort algorithm is implemented to take advantage of
|
|
|
|
|
subsequences that may be already in the desired ordering prior to
|
|
|
|
|
the subroutine call; this situation is relatively common when dealing
|
|
|
|
|
with groups of indices of sparse matrix entries, thus merge-sort is
|
|
|
|
|
|