summaryrefslogtreecommitdiff
path: root/gr-trellis/src/lib/quicksort_index.cc
diff options
context:
space:
mode:
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 cffab8e02..0b577ff05 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);