Go to the documentation of this file.
15 #ifndef ABSL_RANDOM_ZIPF_DISTRIBUTION_H_
16 #define ABSL_RANDOM_ZIPF_DISTRIBUTION_H_
23 #include <type_traits>
25 #include "absl/random/internal/iostream_state_saver.h"
26 #include "absl/random/internal/traits.h"
27 #include "absl/random/uniform_real_distribution.h"
51 template <
typename IntType =
int>
66 double q = 2.0,
double v = 1.0);
69 double q()
const {
return q_; }
70 double v()
const {
return v_; }
73 return a.k_ ==
b.k_ &&
a.q_ ==
b.q_ &&
a.v_ ==
b.v_;
81 inline double h(
double x)
const;
82 inline double hinv(
double x)
const;
99 "Class-template absl::zipf_distribution<> must be "
100 "parameterized using an integral type.");
113 template <
typename URBG>
118 template <
typename URBG>
120 const param_type&
p);
134 return a.param_ ==
b.param_;
138 return a.param_ !=
b.param_;
149 template <
typename IntType>
152 :
k_(
k), q_(q), v_(
v), one_minus_q_(1 - q) {
156 one_minus_q_inv_ = 1 / one_minus_q_;
160 constexpr
double kMax = 18446744073709549568.0;
161 double kd =
static_cast<double>(
k);
172 const bool use_precomputed = (
v == 1.0 &&
q == 2.0);
173 const double h0x5 = use_precomputed ? (-1.0 / 1.5)
175 const double elogv_q = (v_ == 1.0) ? 1 : pow_negative_q(v_);
178 hx0_minus_hxm_ = (h0x5 - elogv_q) - hxm_;
181 s_ = use_precomputed ? 0.46153846153846123 : compute_s();
184 template <
typename IntType>
193 template <
typename IntType>
196 return -v_ + ((one_minus_q_ == -1.0)
198 : std::exp(one_minus_q_inv_ *
std::log(one_minus_q_ *
x)));
201 template <
typename IntType>
204 return 1.0 - hinv(h(1.5) - pow_negative_q(v_ + 1.0));
207 template <
typename IntType>
210 return q_ == 2.0 ? (1.0 / (
x *
x)) : std::exp(
std::log(
x) * -q_);
213 template <
typename IntType>
214 template <
typename URBG>
221 const double v = uniform_double(
g);
222 const double u =
p.hxm_ +
v *
p.hx0_minus_hxm_;
223 const double x =
p.hinv(
u);
225 if (
k >
static_cast<double>(
p.k()))
continue;
226 if (
k -
x <=
p.s_)
break;
227 const double h =
p.h(
k + 0.5);
228 const double r =
p.pow_negative_q(
p.v_ +
k);
229 if (
u >= h -
r)
break;
231 IntType ki =
static_cast<IntType
>(
k);
236 template <
typename CharT,
typename Traits,
typename IntType>
238 std::basic_ostream<CharT, Traits>& os,
244 os << static_cast<stream_type>(
x.k()) << os.fill() <<
x.q() << os.fill()
249 template <
typename CharT,
typename Traits,
typename IntType>
251 std::basic_istream<CharT, Traits>& is,
272 #endif // ABSL_RANDOM_ZIPF_DISTRIBUTION_H_
friend class zipf_distribution
friend bool operator!=(const zipf_distribution &a, const zipf_distribution &b)
istream_state_saver< std::basic_istream< CharT, Traits > > make_istream_state_saver(std::basic_istream< CharT, Traits > &is, std::ios_base::fmtflags flags=std::ios_base::dec|std::ios_base::scientific|std::ios_base::skipws)
ABSL_NAMESPACE_BEGIN std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
friend bool operator==(const zipf_distribution &a, const zipf_distribution &b)
OPENSSL_EXPORT pem_password_cb void * u
#define ABSL_NAMESPACE_END
friend bool operator==(const param_type &a, const param_type &b)
double hinv(double x) const
void param(const param_type &p)
#define ABSL_NAMESPACE_BEGIN
friend bool operator!=(const param_type &a, const param_type &b)
result_type() max() const
constexpr uint128 operator>>(uint128 lhs, int amount)
result_type operator()(URBG &g)
double pow_negative_q(double x) const
param_type(result_type k=(std::numeric_limits< IntType >::max)(), double q=2.0, double v=1.0)
result_type() min() const
ostream_state_saver< std::basic_ostream< CharT, Traits > > make_ostream_state_saver(std::basic_ostream< CharT, Traits > &os, std::ios_base::fmtflags flags=std::ios_base::dec|std::ios_base::left|std::ios_base::scientific)
zipf_distribution(const param_type &p)
zipf_distribution(result_type k, double q=2.0, double v=1.0)
grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:01