| 35 | |
| 36 | template<class STORE> |
| 37 | static void SortImpl(ELEM* inArray, const int inLength, SorterFunc inSorter) |
| 38 | { |
| 39 | auto index = std::vector<STORE>(inLength); |
| 40 | for (auto i = 0; i < inLength; i++) |
| 41 | { |
| 42 | index[i] = static_cast<STORE>(i); |
| 43 | } |
| 44 | |
| 45 | std::stable_sort(index.begin(), index.end(), ArraySorter(inArray, inSorter)); |
| 46 | |
| 47 | // Put the results back ... |
| 48 | for (int i = 0; i < inLength; i++) |
| 49 | { |
| 50 | int from = index[i]; |
| 51 | while (from < i) |
| 52 | from = index[from]; |
| 53 | if (from != i) |
| 54 | { |
| 55 | std::swap(inArray[i], inArray[from]); |
| 56 | index[i] = from; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | public: |
| 62 | static void Sort(ELEM* base, const int length, SorterFunc sorter) |
nothing calls this directly
no test coverage detected