summaryrefslogtreecommitdiff
path: root/gr-trellis/src/lib/quicksort_index.cc
diff options
context:
space:
mode:
authormichaelld <michaelld@221aa14e-8319-0410-a670-987f0aec2ac5>2007-02-06 23:26:05 +0000
committermichaelld <michaelld@221aa14e-8319-0410-a670-987f0aec2ac5>2007-02-06 23:26:05 +0000
commit552c2aa5e5900697e3f2bcc38dc381662af5b8d6 (patch)
tree4dd650995e021d80f25df3ed0feb3b21e0798e25 /gr-trellis/src/lib/quicksort_index.cc
parent529ce3118a00af873c846e98f43d95f1eed7ceb6 (diff)
Added explicit template instantiation.
Removed unneeded non-template code. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4400 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gr-trellis/src/lib/quicksort_index.cc')
-rw-r--r--gr-trellis/src/lib/quicksort_index.cc77
1 files changed, 28 insertions, 49 deletions
diff --git a/gr-trellis/src/lib/quicksort_index.cc b/gr-trellis/src/lib/quicksort_index.cc
index cffab8e02c..0b577ff053 100644
--- a/gr-trellis/src/lib/quicksort_index.cc
+++ b/gr-trellis/src/lib/quicksort_index.cc
@@ -22,68 +22,47 @@
#include "quicksort_index.h"
-template <class T> void SWAP (T & a, T & b)
+template <class T>
+void
+SWAP
+(T & a, T & b)
{
-T temp=a;
-a=b;
-b=temp;
+ T temp = a;
+ a = b;
+ b = temp;
}
-
-// standard quicksorting but also return the indices of the sorted data
-// don't know how to make it work with swig...
-template <class T> void quicksort_index(std::vector<T> & p, std::vector<int> & index, int left, int right)
+template <class T>
+void
+quicksort_index
+(std::vector<T> & p, std::vector<int> & index, int left, int right)
{
-
-if (left < right) {
+ if (left < right) {
int i = left;
int j = right + 1;
T pivot = p[left];
do {
- do
- i++;
- while ((p[i] < pivot) && (i < right));
- do
- j--;
- while ((p[j] > pivot) && (j > left));
- if (i < j) {
- SWAP <T> (p[i],p[j]);
- SWAP <int> (index[i],index[j]);
- }
+ do
+ i++;
+ while ((p[i] < pivot) && (i < right));
+ do
+ j--;
+ while ((p[j] > pivot) && (j > left));
+ if (i < j) {
+ SWAP <T> (p[i],p[j]);
+ SWAP <int> (index[i],index[j]);
+ }
} while (i < j);
SWAP <T> (p[left], p[j]);
SWAP <int> (index[left], index[j]);
quicksort_index <T> (p,index, left, j-1);
quicksort_index <T> (p,index, j+1, right);
+ }
}
-}
-
-
-
-// Same as above (only works for int data)
-void quicksort_index1(std::vector<int> & p, std::vector<int> & index, int left, int right)
-{
-if (left < right) {
- int i = left;
- int j = right + 1;
- int pivot = p[left];
- do {
- do
- i++;
- while ((p[i] < pivot) && (i < right));
- do
- j--;
- while ((p[j] > pivot) && (j > left));
- if (i < j) {
- SWAP <int> (p[i],p[j]);
- SWAP <int> (index[i],index[j]);
- }
- } while (i < j);
- SWAP <int> (p[left], p[j]);
- SWAP <int> (index[left], index[j]);
- quicksort_index1 (p,index, left, j-1);
- quicksort_index1 (p,index, j+1, right);
-}
-}
+// instantiate an <int> version of the quicksort_index
+template
+void
+quicksort_index<int>
+(std::vector<int> & p, std::vector<int> & index, int left, int right);