This is an automated email from the ASF dual-hosted git repository.

xyz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new f7e493b  Remove the Boost.Random dependency (#380)
f7e493b is described below

commit f7e493b593223d0e961f0babbbb47809a4123126
Author: Yunze Xu <[email protected]>
AuthorDate: Fri Jan 5 14:57:50 2024 +0800

    Remove the Boost.Random dependency (#380)
    
    Master issue: https://github.com/apache/pulsar-client-cpp/issues/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`
---
 lib/Backoff.cc                 | 3 +--
 lib/Backoff.h                  | 4 ++--
 lib/RoundRobinMessageRouter.cc | 7 +++----
 vcpkg.json                     | 4 ----
 4 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/lib/Backoff.cc b/lib/Backoff.cc
index 4d95422..fdb1359 100644
--- a/lib/Backoff.cc
+++ b/lib/Backoff.cc
@@ -21,7 +21,6 @@
 #include <time.h> /* time */
 
 #include <algorithm>
-#include <boost/random/uniform_int_distribution.hpp>
 
 namespace pulsar {
 
@@ -47,7 +46,7 @@ TimeDuration Backoff::next() {
         }
     }
     // Add Randomness
-    boost::random::uniform_int_distribution<int> dist;
+    std::uniform_int_distribution<int> dist;
     int randomNumber = dist(rng_);
 
     current = current - (current * (randomNumber % 10) / 100);
diff --git a/lib/Backoff.h b/lib/Backoff.h
index 4bcebc7..a59c00f 100644
--- a/lib/Backoff.h
+++ b/lib/Backoff.h
@@ -21,7 +21,7 @@
 #include <pulsar/defines.h>
 
 #include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/random/mersenne_twister.hpp>
+#include <random>
 
 namespace pulsar {
 
@@ -39,7 +39,7 @@ class PULSAR_PUBLIC Backoff {
     TimeDuration next_;
     TimeDuration mandatoryStop_;
     boost::posix_time::ptime firstBackoffTime_;
-    boost::random::mt19937 rng_;
+    std::mt19937 rng_;
     bool mandatoryStopMade_ = false;
 
     friend class PulsarFriend;
diff --git a/lib/RoundRobinMessageRouter.cc b/lib/RoundRobinMessageRouter.cc
index e33f8d9..9693cc2 100644
--- a/lib/RoundRobinMessageRouter.cc
+++ b/lib/RoundRobinMessageRouter.cc
@@ -18,8 +18,7 @@
  */
 #include "RoundRobinMessageRouter.h"
 
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/uniform_int_distribution.hpp>
+#include <random>
 
 #include "Hash.h"
 #include "TimeUtils.h"
@@ -37,8 +36,8 @@ 
RoundRobinMessageRouter::RoundRobinMessageRouter(ProducerConfiguration::HashingS
       lastPartitionChange_(TimeUtils::currentTimeMillis()),
       msgCounter_(0),
       cumulativeBatchSize_(0) {
-    boost::random::mt19937 rng(time(nullptr));
-    boost::random::uniform_int_distribution<int> dist;
+    std::mt19937 rng(time(nullptr));
+    std::uniform_int_distribution<int> dist;
     currentPartitionCursor_ = dist(rng);
 }
 
diff --git a/vcpkg.json b/vcpkg.json
index 1f9ed97..d023a40 100644
--- a/vcpkg.json
+++ b/vcpkg.json
@@ -36,10 +36,6 @@
       "name": "boost-property-tree",
       "version>=": "1.83.0"
     },
-    {
-      "name": "boost-random",
-      "version>=": "1.83.0"
-    },
     {
       "name": "boost-serialization",
       "version>=": "1.83.0"

Reply via email to