Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Jun 2023 10:59:28 GMT
From:      =?utf-8?Q?Stefan=20E=C3=9Fer?= <se@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 2c1a536ebca3 - main - math/sound-of-sorting: fix build on 14-CURRENT
Message-ID:  <202306281059.35SAxSO0075964@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by se:

URL: https://cgit.FreeBSD.org/ports/commit/?id=2c1a536ebca3d3cf933f46193731e271c10be29e

commit 2c1a536ebca3d3cf933f46193731e271c10be29e
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2023-06-28 10:57:44 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2023-06-28 10:57:44 +0000

    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.
---
 math/sound-of-sorting/files/patch-src_SortAlgo.cpp | 21 +++++++++
 .../sound-of-sorting/files/patch-src_SortArray.cpp | 54 ++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/math/sound-of-sorting/files/patch-src_SortAlgo.cpp b/math/sound-of-sorting/files/patch-src_SortAlgo.cpp
new file mode 100644
index 000000000000..596e78a99cf8
--- /dev/null
+++ b/math/sound-of-sorting/files/patch-src_SortAlgo.cpp
@@ -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);
diff --git a/math/sound-of-sorting/files/patch-src_SortArray.cpp b/math/sound-of-sorting/files/patch-src_SortArray.cpp
new file mode 100644
index 000000000000..29184f4f63ba
--- /dev/null
+++ b/math/sound-of-sorting/files/patch-src_SortArray.cpp
@@ -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
+     {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202306281059.35SAxSO0075964>