diff options
author | michaelld | 2007-02-06 23:26:05 +0000 |
---|---|---|
committer | michaelld | 2007-02-06 23:26:05 +0000 |
commit | 552c2aa5e5900697e3f2bcc38dc381662af5b8d6 (patch) | |
tree | 4dd650995e021d80f25df3ed0feb3b21e0798e25 | |
parent | 529ce3118a00af873c846e98f43d95f1eed7ceb6 (diff) | |
download | gnuradio-552c2aa5e5900697e3f2bcc38dc381662af5b8d6.tar.gz gnuradio-552c2aa5e5900697e3f2bcc38dc381662af5b8d6.tar.bz2 gnuradio-552c2aa5e5900697e3f2bcc38dc381662af5b8d6.zip |
Added explicit template instantiation.
Removed unneeded non-template code.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4400 221aa14e-8319-0410-a670-987f0aec2ac5
-rw-r--r-- | gr-trellis/src/lib/interleaver.cc | 6 | ||||
-rw-r--r-- | gr-trellis/src/lib/quicksort_index.cc | 77 | ||||
-rw-r--r-- | gr-trellis/src/lib/quicksort_index.h | 11 |
3 files changed, 37 insertions, 57 deletions
diff --git a/gr-trellis/src/lib/interleaver.cc b/gr-trellis/src/lib/interleaver.cc index b33ac5b2d..33556ea45 100644 --- a/gr-trellis/src/lib/interleaver.cc +++ b/gr-trellis/src/lib/interleaver.cc @@ -91,18 +91,16 @@ interleaver::interleaver(int K, unsigned int seed) d_INTER.resize(d_K); d_DEINTER.resize(d_K); - srand(seed); + srand(seed); std::vector<int> tmp(d_K); for(int i=0;i<d_K;i++) { d_INTER[i]=i; tmp[i] = rand(); } - //quicksort_index <int> (tmp,d_INTER,0,d_K-1); //got to resolve this... - quicksort_index1 (tmp,d_INTER,0,d_K-1); + quicksort_index <int> (tmp,d_INTER,0,d_K-1); // generate DEINTER table for(int i=0;i<d_K;i++) { d_DEINTER[d_INTER[i]]=i; } } - 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); diff --git a/gr-trellis/src/lib/quicksort_index.h b/gr-trellis/src/lib/quicksort_index.h index 8f8702354..b519b66c9 100644 --- a/gr-trellis/src/lib/quicksort_index.h +++ b/gr-trellis/src/lib/quicksort_index.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2007 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,8 +25,11 @@ #include <vector> -template <class T> void SWAP (T & a, T & b); -template <class T> void quicksort_index(std::vector<T> & p, std::vector<int> & index, int left, int right); -void quicksort_index1(std::vector<int> & p, std::vector<int> & index, int left, int right); +template <class T> +void SWAP (T & a, T & b); + +template <class T> +void quicksort_index (std::vector<T> & p, std::vector<int> & index, + int left, int right); #endif |