math/sound-of-sorting: fix build on 14-CURRENT
The random_shuffle() function has been removed from C++17. Use shuffle() with a suitable pseudo-random generator instead.
This commit is contained in:
parent
71c970cb29
commit
2c1a536ebc
2 changed files with 75 additions and 0 deletions
21
math/sound-of-sorting/files/patch-src_SortAlgo.cpp
Normal file
21
math/sound-of-sorting/files/patch-src_SortAlgo.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
--- src/SortAlgo.cpp.orig 2017-12-23 08:39:32 UTC
|
||||
+++ src/SortAlgo.cpp
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <numeric>
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
+#include <random>
|
||||
|
||||
typedef ArrayItem value_type;
|
||||
|
||||
@@ -1076,7 +1077,9 @@ void BogoSort(SortArray& A)
|
||||
if (BogoCheckSorted(A)) break;
|
||||
|
||||
// pick a random permutation of indexes
|
||||
- std::random_shuffle(perm.begin(), perm.end());
|
||||
+ std::random_device rng;
|
||||
+ std::mt19937 urng(rng());
|
||||
+ std::shuffle(perm.begin(), perm.end(), urng);
|
||||
|
||||
// permute array in-place
|
||||
std::vector<char> pmark(A.size(), 0);
|
54
math/sound-of-sorting/files/patch-src_SortArray.cpp
Normal file
54
math/sound-of-sorting/files/patch-src_SortArray.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
--- src/SortArray.cpp.orig 2017-12-23 08:39:32 UTC
|
||||
+++ src/SortArray.cpp
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "SortAlgo.h"
|
||||
|
||||
#include <algorithm>
|
||||
+#include <random>
|
||||
|
||||
extern void SoundAccess(size_t i);
|
||||
|
||||
@@ -123,7 +124,9 @@ void SortArray::FillData(unsigned int schema, size_t a
|
||||
for (size_t i = 0; i < m_array.size(); ++i)
|
||||
m_array[i] = ArrayItem(i+1);
|
||||
|
||||
- std::random_shuffle(m_array.begin(), m_array.end());
|
||||
+ std::random_device rng;
|
||||
+ std::mt19937 urng(rng());
|
||||
+ std::shuffle(m_array.begin(), m_array.end(), urng);
|
||||
}
|
||||
else if (schema == 1) // Ascending [1,n]
|
||||
{
|
||||
@@ -150,7 +153,9 @@ void SortArray::FillData(unsigned int schema, size_t a
|
||||
m_array[i] = ArrayItem(w + 1);
|
||||
}
|
||||
|
||||
- std::random_shuffle(m_array.begin(), m_array.end());
|
||||
+ std::random_device rng;
|
||||
+ std::mt19937 urng(rng());
|
||||
+ std::shuffle(m_array.begin(), m_array.end(), urng);
|
||||
}
|
||||
else if (schema == 4) // Quintic skew of [1,n]
|
||||
{
|
||||
@@ -167,7 +172,9 @@ void SortArray::FillData(unsigned int schema, size_t a
|
||||
m_array[i] = ArrayItem(w + 1);
|
||||
}
|
||||
|
||||
- std::random_shuffle(m_array.begin(), m_array.end());
|
||||
+ std::random_device rng;
|
||||
+ std::mt19937 urng(rng());
|
||||
+ std::shuffle(m_array.begin(), m_array.end(), urng);
|
||||
}
|
||||
else if (schema == 5) // shuffled n-2 equal values in [1,n]
|
||||
{
|
||||
@@ -178,7 +185,9 @@ void SortArray::FillData(unsigned int schema, size_t a
|
||||
}
|
||||
m_array[m_array.size()-1] = ArrayItem(arraysize);
|
||||
|
||||
- std::random_shuffle(m_array.begin(), m_array.end());
|
||||
+ std::random_device rng;
|
||||
+ std::mt19937 urng(rng());
|
||||
+ std::shuffle(m_array.begin(), m_array.end(), urng);
|
||||
}
|
||||
else // fallback
|
||||
{
|
Loading…
Reference in a new issue