From 0eb371e7a13de3382afabdfea957bb41abf78860 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 10 Feb 2015 18:50:01 +0000 Subject: [PATCH] base: use an explicit enum class for sort algorithm names. --- src/lol/algorithm/sort.h | 21 +++++++++++++-------- src/lol/base/array.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lol/algorithm/sort.h b/src/lol/algorithm/sort.h index 8a7bee5a..06629568 100644 --- a/src/lol/algorithm/sort.h +++ b/src/lol/algorithm/sort.h @@ -18,6 +18,12 @@ namespace lol { +enum class SortAlgorithm : uint8_t +{ + QuickSwap, + Bubble, +}; + template void array_base::Shuffle() { @@ -31,14 +37,15 @@ void array_base::Shuffle() } template -void array_base::Sort(int sort) +void array_base::Sort(SortAlgorithm algorithm) { -#if SORT_WORKS // yeah cause it's shite. - int s = 0; +#if !SORT_WORKS // yeah cause it's shite. + algorithm = SortAlgorithm::Bubble; +#endif + // Classic bubble - if (s++ == sort) + if (algorithm == SortAlgorithm::Bubble) { -#endif //SORT_WORKS int d = 1; for (ptrdiff_t i = 0; i < Count() - 1; i = lol::max(i + d, (ptrdiff_t)0)) { @@ -50,14 +57,12 @@ void array_base::Sort(int sort) d = -1; } } -#if SORT_WORKS } // Quick sort with swap - else if (s++ == sort) + else if (algorithm == SortAlgorithm::QuickSwap) { SortQuickSwap(0, Count()); } -#endif //SORT_WORKS } template diff --git a/src/lol/base/array.h b/src/lol/base/array.h index 95a29722..e71c9f91 100644 --- a/src/lol/base/array.h +++ b/src/lol/base/array.h @@ -383,7 +383,7 @@ public: } void Shuffle(); - void Sort(int sort = 0); + void Sort(enum class SortAlgorithm : uint8_t); void SortQuickSwap(ptrdiff_t start, ptrdiff_t stop); /* TODO: remove these legacy functions one day */