commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4400 - gnuradio/trunk/gr-trellis/src/lib


From: michaelld
Subject: [Commit-gnuradio] r4400 - gnuradio/trunk/gr-trellis/src/lib
Date: Tue, 6 Feb 2007 16:26:05 -0700 (MST)

Author: michaelld
Date: 2007-02-06 16:26:05 -0700 (Tue, 06 Feb 2007)
New Revision: 4400

Modified:
   gnuradio/trunk/gr-trellis/src/lib/interleaver.cc
   gnuradio/trunk/gr-trellis/src/lib/quicksort_index.cc
   gnuradio/trunk/gr-trellis/src/lib/quicksort_index.h
Log:
Added explicit template instantiation.
Removed unneeded non-template code.



Modified: gnuradio/trunk/gr-trellis/src/lib/interleaver.cc
===================================================================
--- gnuradio/trunk/gr-trellis/src/lib/interleaver.cc    2007-02-06 23:24:07 UTC 
(rev 4399)
+++ gnuradio/trunk/gr-trellis/src/lib/interleaver.cc    2007-02-06 23:26:05 UTC 
(rev 4400)
@@ -91,18 +91,16 @@
   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;
   }
 }
-

Modified: gnuradio/trunk/gr-trellis/src/lib/quicksort_index.cc
===================================================================
--- gnuradio/trunk/gr-trellis/src/lib/quicksort_index.cc        2007-02-06 
23:24:07 UTC (rev 4399)
+++ gnuradio/trunk/gr-trellis/src/lib/quicksort_index.cc        2007-02-06 
23:26:05 UTC (rev 4400)
@@ -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);
+  }
 }
-}
 
+// instantiate an <int> version of the quicksort_index
 
-
-// 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);
-}
-}
-
+template
+void
+quicksort_index<int>
+(std::vector<int> & p, std::vector<int> & index, int left, int right);

Modified: gnuradio/trunk/gr-trellis/src/lib/quicksort_index.h
===================================================================
--- gnuradio/trunk/gr-trellis/src/lib/quicksort_index.h 2007-02-06 23:24:07 UTC 
(rev 4399)
+++ gnuradio/trunk/gr-trellis/src/lib/quicksort_index.h 2007-02-06 23:26:05 UTC 
(rev 4400)
@@ -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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]