summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/move/test/random_shuffle.hpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/move/test/random_shuffle.hpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/move/test/random_shuffle.hpp')
-rw-r--r--src/boost/libs/move/test/random_shuffle.hpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/boost/libs/move/test/random_shuffle.hpp b/src/boost/libs/move/test/random_shuffle.hpp
new file mode 100644
index 00000000..907d195f
--- /dev/null
+++ b/src/boost/libs/move/test/random_shuffle.hpp
@@ -0,0 +1,37 @@
+#ifndef BOOST_MOVE_TEST_RANDOM_SHUFFLE_HPP
+#define BOOST_MOVE_TEST_RANDOM_SHUFFLE_HPP
+
+
+#include <boost/move/adl_move_swap.hpp>
+#include <boost/move/detail/iterator_traits.hpp>
+#include <stdlib.h>
+
+inline unsigned long long rand_15_bit()
+{
+ //Many rand implementation only use 15 bits
+ //so make sure we have only 15 bits
+ return (unsigned long long)((std::rand()) & 0x7fffu);
+}
+
+inline unsigned long long ullrand()
+{
+ return (rand_15_bit() << 54u) ^ (rand_15_bit() << 39u)
+ ^ (rand_15_bit() << 26u) ^ (rand_15_bit() << 13u)
+ ^ rand_15_bit();
+}
+
+template< class RandomIt >
+void random_shuffle( RandomIt first, RandomIt last )
+{
+ typedef typename boost::movelib::iterator_traits<RandomIt>::difference_type difference_type;
+ difference_type n = last - first;
+ for (difference_type i = n-1; i > 0; --i) {
+ difference_type j = ullrand() % (i+1);
+ if(j != i) {
+ boost::adl_move_swap(first[i], first[j]);
+ }
+ }
+}
+
+
+#endif// BOOST_MOVE_TEST_RANDOM_SHUFFLE_HPP