Browse Source

base: use an explicit enum class for sort algorithm names.

undefined
Sam Hocevar 9 years ago
parent
commit
0eb371e7a1
2 changed files with 14 additions and 9 deletions
  1. +13
    -8
      src/lol/algorithm/sort.h
  2. +1
    -1
      src/lol/base/array.h

+ 13
- 8
src/lol/algorithm/sort.h View File

@@ -18,6 +18,12 @@
namespace lol namespace lol
{ {


enum class SortAlgorithm : uint8_t
{
QuickSwap,
Bubble,
};

template<typename T, typename ARRAY> template<typename T, typename ARRAY>
void array_base<T, ARRAY>::Shuffle() void array_base<T, ARRAY>::Shuffle()
{ {
@@ -31,14 +37,15 @@ void array_base<T, ARRAY>::Shuffle()
} }


template<typename T, typename ARRAY> template<typename T, typename ARRAY>
void array_base<T, ARRAY>::Sort(int sort)
void array_base<T, ARRAY>::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 // Classic bubble
if (s++ == sort)
if (algorithm == SortAlgorithm::Bubble)
{ {
#endif //SORT_WORKS
int d = 1; int d = 1;
for (ptrdiff_t i = 0; i < Count() - 1; i = lol::max(i + d, (ptrdiff_t)0)) for (ptrdiff_t i = 0; i < Count() - 1; i = lol::max(i + d, (ptrdiff_t)0))
{ {
@@ -50,14 +57,12 @@ void array_base<T, ARRAY>::Sort(int sort)
d = -1; d = -1;
} }
} }
#if SORT_WORKS
} }
// Quick sort with swap // Quick sort with swap
else if (s++ == sort)
else if (algorithm == SortAlgorithm::QuickSwap)
{ {
SortQuickSwap(0, Count()); SortQuickSwap(0, Count());
} }
#endif //SORT_WORKS
} }


template<typename T, typename ARRAY> template<typename T, typename ARRAY>


+ 1
- 1
src/lol/base/array.h View File

@@ -383,7 +383,7 @@ public:
} }


void Shuffle(); void Shuffle();
void Sort(int sort = 0);
void Sort(enum class SortAlgorithm : uint8_t);
void SortQuickSwap(ptrdiff_t start, ptrdiff_t stop); void SortQuickSwap(ptrdiff_t start, ptrdiff_t stop);


/* TODO: remove these legacy functions one day */ /* TODO: remove these legacy functions one day */


Loading…
Cancel
Save