Eliminate dependency on Boost.Random
Also replace use of std::random_shuffle (removed in C++17)
with std::shuffle.
Change-Id: I200a8a404e67447c547c9abfa1a5a55a18de9ef3
diff --git a/examples/data-producer.cpp b/examples/data-producer.cpp
index 20692c5..806c011 100644
--- a/examples/data-producer.cpp
+++ b/examples/data-producer.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -34,21 +34,20 @@
*/
#include "../src/common.hpp"
-#include <fstream>
-#include <boost/filesystem.hpp>
+
#include <boost/lexical_cast.hpp>
-#include <string>
-#include <boost/random.hpp>
+#include <fstream>
#include <iostream>
+#include <random>
+#include <string>
namespace repo {
-using namespace ndn::time;
+using ndn::time::milliseconds;
static const milliseconds DEFAULT_TIME_INTERVAL(2000);
-enum Mode
-{
+enum Mode {
AUTO,
READFILE
};
@@ -73,8 +72,9 @@
, timeInterval(DEFAULT_TIME_INTERVAL)
, duration(0)
, m_scheduler(m_face.getIoService())
- , m_randomGenerator(static_cast<unsigned int> (0))
- , m_range(m_randomGenerator, boost::uniform_int<> (200,1000))
+ , m_randomEngine(std::random_device{}())
+ , m_randomDist(200, 1000)
+ , m_range([this] { return m_randomDist(m_randomEngine); })
{
}
@@ -89,6 +89,7 @@
std::shared_ptr<ndn::Data>
createData(const ndn::Name& name);
+
public:
std::ifstream insertStream;
Mode mode;
@@ -99,14 +100,14 @@
private:
ndn::Face m_face;
ndn::Scheduler m_scheduler;
- boost::mt19937 m_randomGenerator;
- boost::variate_generator<boost::mt19937&, boost::uniform_int<> > m_range;
+ std::mt19937 m_randomEngine;
+ std::uniform_int_distribution<unsigned int> m_randomDist;
+ std::function<unsigned int(void)> m_range;
};
void
Publisher::run()
{
-
if (mode == AUTO) {
m_scheduler.scheduleEvent(timeInterval,
bind(&Publisher::autoGenerate, this));
@@ -171,7 +172,7 @@
exit(1);
}
-int
+static int
main(int argc, char** argv)
{
Publisher generator;
diff --git a/src/common.hpp b/src/common.hpp
index ecd0719..6b7c7b9 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -33,19 +33,15 @@
#include <ndn-cxx/util/scheduler.hpp>
#include <boost/utility.hpp>
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/uniform_int_distribution.hpp>
-#include <boost/random/geometric_distribution.hpp>
+#include <algorithm>
+#include <functional>
+#include <iostream>
+#include <list>
#include <map>
+#include <memory>
#include <string>
#include <vector>
-#include <queue>
-#include <list>
-#include <algorithm>
-#include <iostream>
-#include <functional>
-#include <memory>
namespace repo {
diff --git a/src/handles/base-handle.cpp b/src/handles/base-handle.cpp
index 76fa36c..8555f39 100644
--- a/src/handles/base-handle.cpp
+++ b/src/handles/base-handle.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014, Regents of the University of California.
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -19,14 +19,14 @@
#include "base-handle.hpp"
+#include <ndn-cxx/util/random.hpp>
+
namespace repo {
uint64_t
BaseHandle::generateProcessId()
{
- static boost::random::mt19937_64 gen;
- static boost::random::uniform_int_distribution<uint64_t> dist(0, 0xFFFFFFFFFFFFFFFFLL);
- return dist(gen);
+ return ndn::random::generateWord64();
}
-}
+} // namespace repo
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index 28fea81..ff4b866 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -27,9 +27,9 @@
#include "../dataset-fixtures.hpp"
#include <ndn-cxx/util/random.hpp>
-#include <boost/preprocessor/comparison/not_equal.hpp>
+
+#include <boost/mpl/vector.hpp>
#include <boost/test/unit_test.hpp>
-#include <fstream>
namespace repo {
namespace tests {
@@ -37,9 +37,8 @@
using ndn::time::milliseconds;
using ndn::time::seconds;
using ndn::EventId;
-namespace random=ndn::random;
-//All the test cases in this test suite should be run at once.
+// All the test cases in this test suite should be run at once.
BOOST_AUTO_TEST_SUITE(TestBasicCommandInsertDelete)
const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
@@ -225,7 +224,7 @@
Name insertCommandName("/repo/command/insert");
RepoCommandParameter insertParameter;
insertParameter.setName(Name((*i)->getName())
- .appendNumber(random::generateWord64()));
+ .appendNumber(ndn::random::generateWord64()));
insertCommandName.append(insertParameter.wireEncode());
Interest insertInterest(insertCommandName);
@@ -256,9 +255,7 @@
i != this->data.end(); ++i) {
Name deleteCommandName("/repo/command/delete");
RepoCommandParameter deleteParameter;
- static boost::random::mt19937_64 gen;
- static boost::random::uniform_int_distribution<uint64_t> dist(0, 0xFFFFFFFFFFFFFFFFLL);
- deleteParameter.setProcessId(dist(gen));
+ deleteParameter.setProcessId(ndn::random::generateWord64());
deleteParameter.setName((*i)->getName());
deleteCommandName.append(deleteParameter.wireEncode());
Interest deleteInterest(deleteCommandName);
diff --git a/tests/integrated/test-basic-command-watch.cpp b/tests/integrated/test-basic-command-watch.cpp
index a29deed..1e38da9 100644
--- a/tests/integrated/test-basic-command-watch.cpp
+++ b/tests/integrated/test-basic-command-watch.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -26,8 +26,8 @@
#include <ndn-cxx/util/random.hpp>
+#include <boost/mpl/vector.hpp>
#include <boost/test/unit_test.hpp>
-#include <fstream>
namespace repo {
namespace tests {
@@ -35,9 +35,8 @@
using ndn::time::milliseconds;
using ndn::time::seconds;
using ndn::EventId;
-namespace random = ndn::random;
-//All the test cases in this test suite should be run at once.
+// All the test cases in this test suite should be run at once.
BOOST_AUTO_TEST_SUITE(TestBasicCommandWatchDelete)
const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
@@ -97,7 +96,8 @@
template<class T> void
Fixture<T>::onWatchInterest(const Interest& interest)
{
- shared_ptr<Data> data = make_shared<Data>(Name(interest.getName()).appendNumber(random::generateWord64()+100));
+ auto data = make_shared<Data>(Name(interest.getName())
+ .appendNumber(ndn::random::generateWord64() + 100));
data->setContent(content, sizeof(content));
data->setFreshnessPeriod(milliseconds(0));
keyChain.sign(*data);
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index eb412e8..cb10c89 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -24,14 +24,12 @@
#include "../repo-storage-fixture.hpp"
#include "../dataset-fixtures.hpp"
-#include <ndn-cxx/util/random.hpp>
-
#include <boost/test/unit_test.hpp>
namespace repo {
namespace tests {
-//All the test cases in this test suite should be run at once.
+// All the test cases in this test suite should be run at once.
BOOST_AUTO_TEST_SUITE(TestBasicInerestRead)
const static uint8_t content[8] = {3, 1, 4, 1, 5, 9, 2, 6};
diff --git a/tests/other/skiplist-list.hpp b/tests/other/skiplist-list.hpp
index 72d1dda..ca71c7f 100644
--- a/tests/other/skiplist-list.hpp
+++ b/tests/other/skiplist-list.hpp
@@ -1,26 +1,29 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
-* Copyright (c) 2014, Regents of the University of California.
-*
-* This file is part of NDN repo-ng (Next generation of NDN repository).
-* See AUTHORS.md for complete list of repo-ng authors and contributors.
-*
-* repo-ng is free software: you can redistribute it and/or modify it under the terms
-* of the GNU General Public License as published by the Free Software Foundation,
-* either version 3 of the License, or (at your option) any later version.
-*
-* repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-* PURPOSE. See the GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License along with
-* repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
-*/
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
+ *
+ * This file is part of NDN repo-ng (Next generation of NDN repository).
+ * See AUTHORS.md for complete list of repo-ng authors and contributors.
+ *
+ * repo-ng is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
#ifndef REPO_TESTS_OTHER_SKIPLIST_LIST_HPP
#define REPO_TESTS_OTHER_SKIPLIST_LIST_HPP
+
#include "common.hpp"
+#include <random>
+
namespace update1 {
class SkipList32Levels25Probabilty
@@ -136,7 +139,7 @@
}
};
-/*
+/**
* @brief SkipList
*
* Examples of internal structure:
@@ -224,7 +227,7 @@
protected:
- /*
+ /**
* @brief initialize the node
*/
NodePointer
@@ -234,9 +237,9 @@
return p;
}
- /*
+ /**
* @brief initialize the node with given value
- * @para to be set to the value of node
+ * @param x to be set to the value of node
*/
NodePointer
createNode(const T& x)
@@ -246,9 +249,9 @@
return p;
}
- /*
- * @brief destructror of the node
- * @para given pointer of node to be destructed
+ /**
+ * @brief destructor of the node
+ * @param p pointer to the node to be destructed
*/
void
destroyNode(NodePointer p)
@@ -256,7 +259,7 @@
delete(p);
}
- /*
+ /**
* @brief initialize the head
*/
void
@@ -268,7 +271,7 @@
m_size = 0;
}
- /*
+ /**
* @brief destroy all the nodes of skiplist except the head
*/
void
@@ -284,14 +287,14 @@
m_head->prevs.front() = m_head;
}
- /*
+ /**
* @brief pick a random height for inserted skiplist entry
*/
size_t
pickRandomLevel() const
{
- static boost::random::mt19937 gen;
- static boost::random::geometric_distribution<size_t> dist(Traits::getProbability());
+ static std::mt19937 gen(std::random_device{}());
+ static std::geometric_distribution<size_t> dist(Traits::getProbability());
return std::min(dist(gen), Traits::getMaxLevels());
}
@@ -473,6 +476,6 @@
}
}
-} //end namespace update1
+} // namespace update1
-#endif // REPO_TESTS_UNIT_SKIPLIST_LIST_HPP
+#endif // REPO_TESTS_OTHER_SKIPLIST_LIST_HPP
diff --git a/tests/other/skiplist-prev.hpp b/tests/other/skiplist-prev.hpp
index 1bb416d..c19ca29 100644
--- a/tests/other/skiplist-prev.hpp
+++ b/tests/other/skiplist-prev.hpp
@@ -1,27 +1,29 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
-* Copyright (c) 2014, Regents of the University of California.
-*
-* This file is part of NDN repo-ng (Next generation of NDN repository).
-* See AUTHORS.md for complete list of repo-ng authors and contributors.
-*
-* repo-ng is free software: you can redistribute it and/or modify it under the terms
-* of the GNU General Public License as published by the Free Software Foundation,
-* either version 3 of the License, or (at your option) any later version.
-*
-* repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-* PURPOSE. See the GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License along with
-* repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
-*/
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
+ *
+ * This file is part of NDN repo-ng (Next generation of NDN repository).
+ * See AUTHORS.md for complete list of repo-ng authors and contributors.
+ *
+ * repo-ng is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
#ifndef REPO_TESTS_OTHER_SKIPLIST_PREV_HPP
#define REPO_TESTS_OTHER_SKIPLIST_PREV_HPP
#include "common.hpp"
+#include <random>
+
namespace prev {
class SkipList32Levels25Probabilty
@@ -312,8 +314,8 @@
size_t
pickRandomLevel() const
{
- static boost::random::mt19937 gen;
- static boost::random::geometric_distribution<size_t> dist(Traits::getProbability());
+ static std::mt19937 gen(std::random_device{}());
+ static std::geometric_distribution<size_t> dist(Traits::getProbability());
return std::min(dist(gen), Traits::getMaxLevels());
}
diff --git a/tests/other/skiplist-vector.hpp b/tests/other/skiplist-vector.hpp
index 6079dd3..8ef1ed9 100644
--- a/tests/other/skiplist-vector.hpp
+++ b/tests/other/skiplist-vector.hpp
@@ -1,26 +1,29 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
-* Copyright (c) 2014, Regents of the University of California.
-*
-* This file is part of NDN repo-ng (Next generation of NDN repository).
-* See AUTHORS.md for complete list of repo-ng authors and contributors.
-*
-* repo-ng is free software: you can redistribute it and/or modify it under the terms
-* of the GNU General Public License as published by the Free Software Foundation,
-* either version 3 of the License, or (at your option) any later version.
-*
-* repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-* PURPOSE. See the GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License along with
-* repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
-*/
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
+ *
+ * This file is part of NDN repo-ng (Next generation of NDN repository).
+ * See AUTHORS.md for complete list of repo-ng authors and contributors.
+ *
+ * repo-ng is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
#ifndef REPO_TESTS_OTHER_SKIPLIST_VECTOR_HPP
#define REPO_TESTS_OTHER_SKIPLIST_VECTOR_HPP
+
#include "common.hpp"
+#include <random>
+
namespace update2 {
class SkipList32Levels25Probabilty
@@ -290,8 +293,8 @@
size_t
pickRandomLevel() const
{
- static boost::random::mt19937 gen;
- static boost::random::geometric_distribution<size_t> dist(Traits::getProbability());
+ static std::mt19937 gen(std::random_device{}());
+ static std::geometric_distribution<size_t> dist(Traits::getProbability());
return std::min(dist(gen), Traits::getMaxLevels());
}
@@ -412,6 +415,6 @@
}
-} //end namespace update2
+} // namespace update2
#endif // REPO_TESTS_OTHER_SKIPLIST_VECTOR_HPP
diff --git a/tests/unit/sqlite-handle.cpp b/tests/unit/sqlite-handle.cpp
index d493e3d..ca7c7dd 100644
--- a/tests/unit/sqlite-handle.cpp
+++ b/tests/unit/sqlite-handle.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014, Regents of the University of California.
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -23,6 +23,7 @@
#include "../dataset-fixtures.hpp"
#include <boost/test/unit_test.hpp>
+#include <random>
namespace repo {
namespace tests {
@@ -33,28 +34,28 @@
class Fixture : public SqliteFixture, public Dataset
{
public:
- std::map<int64_t, shared_ptr<Data> > idToDataMap;
+ std::map<int64_t, shared_ptr<Data>> idToDataMap;
};
BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertReadDelete, T, CommonDatasets, Fixture<T>)
{
- BOOST_TEST_MESSAGE(T::getName());
+ BOOST_TEST_CHECKPOINT(T::getName());
std::vector<int64_t> ids;
// Insert
for (typename T::DataContainer::iterator i = this->data.begin();
- i != this->data.end(); ++i)
- {
- int64_t id = -1;
- BOOST_REQUIRE_NO_THROW(id = this->handle->insert(**i));
+ i != this->data.end(); ++i) {
+ int64_t id = -1;
+ BOOST_REQUIRE_NO_THROW(id = this->handle->insert(**i));
- this->idToDataMap.insert(std::make_pair(id, *i));
- ids.push_back(id);
- }
+ this->idToDataMap.insert(std::make_pair(id, *i));
+ ids.push_back(id);
+ }
BOOST_CHECK_EQUAL(this->handle->size(), static_cast<int64_t>(this->data.size()));
- std::random_shuffle(ids.begin(), ids.end());
+ std::mt19937 rng{std::random_device{}()};
+ std::shuffle(ids.begin(), ids.end(), rng);
// Read (all items should exist)
for (std::vector<int64_t>::iterator i = ids.begin(); i != ids.end(); ++i) {
diff --git a/wscript b/wscript
index f4f4907..3648e2f 100644
--- a/wscript
+++ b/wscript
@@ -34,7 +34,7 @@
conf.env['WITH_TESTS'] = conf.options.with_tests
conf.env['WITH_TOOLS'] = conf.options.with_tools
- USED_BOOST_LIBS = ['system', 'iostreams', 'filesystem', 'random']
+ USED_BOOST_LIBS = ['system', 'iostreams', 'filesystem']
if conf.env['WITH_TESTS']:
USED_BOOST_LIBS += ['unit_test_framework']
conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True)