Skip to content

Commit f7e493b

Browse files
Remove the Boost.Random dependency (#380)
Master issue: #367 ### Motivation We still depends on the Boost.Random dependency on some places, which could be replaced by the C++ standard random library. ### Modifications - Replace Boost.Random usages with the standard `<random>` header - Remove the `boost-random` dependency from `vcpkg.json`
1 parent a4b7f12 commit f7e493b

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

lib/Backoff.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <time.h> /* time */
2222

2323
#include <algorithm>
24-
#include <boost/random/uniform_int_distribution.hpp>
2524

2625
namespace pulsar {
2726

@@ -47,7 +46,7 @@ TimeDuration Backoff::next() {
4746
}
4847
}
4948
// Add Randomness
50-
boost::random::uniform_int_distribution<int> dist;
49+
std::uniform_int_distribution<int> dist;
5150
int randomNumber = dist(rng_);
5251

5352
current = current - (current * (randomNumber % 10) / 100);

lib/Backoff.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <pulsar/defines.h>
2222

2323
#include <boost/date_time/posix_time/posix_time.hpp>
24-
#include <boost/random/mersenne_twister.hpp>
24+
#include <random>
2525

2626
namespace pulsar {
2727

@@ -39,7 +39,7 @@ class PULSAR_PUBLIC Backoff {
3939
TimeDuration next_;
4040
TimeDuration mandatoryStop_;
4141
boost::posix_time::ptime firstBackoffTime_;
42-
boost::random::mt19937 rng_;
42+
std::mt19937 rng_;
4343
bool mandatoryStopMade_ = false;
4444

4545
friend class PulsarFriend;

lib/RoundRobinMessageRouter.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
*/
1919
#include "RoundRobinMessageRouter.h"
2020

21-
#include <boost/random/mersenne_twister.hpp>
22-
#include <boost/random/uniform_int_distribution.hpp>
21+
#include <random>
2322

2423
#include "Hash.h"
2524
#include "TimeUtils.h"
@@ -37,8 +36,8 @@ RoundRobinMessageRouter::RoundRobinMessageRouter(ProducerConfiguration::HashingS
3736
lastPartitionChange_(TimeUtils::currentTimeMillis()),
3837
msgCounter_(0),
3938
cumulativeBatchSize_(0) {
40-
boost::random::mt19937 rng(time(nullptr));
41-
boost::random::uniform_int_distribution<int> dist;
39+
std::mt19937 rng(time(nullptr));
40+
std::uniform_int_distribution<int> dist;
4241
currentPartitionCursor_ = dist(rng);
4342
}
4443

vcpkg.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
"name": "boost-property-tree",
3737
"version>=": "1.83.0"
3838
},
39-
{
40-
"name": "boost-random",
41-
"version>=": "1.83.0"
42-
},
4339
{
4440
"name": "boost-serialization",
4541
"version>=": "1.83.0"

0 commit comments

Comments
 (0)