| 27 | **/ |
| 28 | template <typename VectorV, typename VectorI> |
| 29 | Index QuickSplit(VectorV &row, VectorI &ind, Index ncut) |
| 30 | { |
| 31 | typedef typename VectorV::RealScalar RealScalar; |
| 32 | using std::swap; |
| 33 | using std::abs; |
| 34 | Index mid; |
| 35 | Index n = row.size(); /* length of the vector */ |
| 36 | Index first, last ; |
| 37 | |
| 38 | ncut--; /* to fit the zero-based indices */ |
| 39 | first = 0; |
| 40 | last = n-1; |
| 41 | if (ncut < first || ncut > last ) return 0; |
| 42 | |
| 43 | do { |
| 44 | mid = first; |
| 45 | RealScalar abskey = abs(row(mid)); |
| 46 | for (Index j = first + 1; j <= last; j++) { |
| 47 | if ( abs(row(j)) > abskey) { |
| 48 | ++mid; |
| 49 | swap(row(mid), row(j)); |
| 50 | swap(ind(mid), ind(j)); |
| 51 | } |
| 52 | } |
| 53 | /* Interchange for the pivot element */ |
| 54 | swap(row(mid), row(first)); |
| 55 | swap(ind(mid), ind(first)); |
| 56 | |
| 57 | if (mid > ncut) last = mid - 1; |
| 58 | else if (mid < ncut ) first = mid + 1; |
| 59 | } while (mid != ncut ); |
| 60 | |
| 61 | return 0; /* mid is equal to ncut */ |
| 62 | } |
| 63 | |
| 64 | }// end namespace internal |
| 65 | |