|
29 | 29 |
|
30 | 30 | /*
|
31 | 31 | * The zipfian_int_distribution class is intended to be compatible with other
|
32 |
| - * distributions defined in #include<random> by the C++11 standard. |
| 32 | + * distributions introduced in #include <random> by the C++11 standard. |
33 | 33 | *
|
34 | 34 | * Usage example:
|
35 | 35 | * #include <random>
|
36 | 36 | * #include "zipfian_int_distribution.h"
|
37 | 37 | * int main()
|
38 | 38 | * {
|
39 | 39 | * std::default_random_engine generator;
|
40 |
| - * zipfian_int_distribution<int> distribution(1,10,0.99); |
| 40 | + * zipfian_int_distribution<int> distribution(1, 10, 0.99); |
41 | 41 | * int i = distribution(generator);
|
42 | 42 | * }
|
43 | 43 | */
|
|
46 | 46 | * IMPORTANT: constructing the distribution object requires calculating the zeta
|
47 | 47 | * value which becomes prohibetively expensive for very large ranges. As an
|
48 | 48 | * alternative for such cases, the user can pass the pre-calculated values and
|
49 |
| - * avoid the calculation. |
| 49 | + * avoid the calculation every time. |
50 | 50 | *
|
51 | 51 | * Usage example:
|
52 | 52 | * #include <random>
|
53 | 53 | * #include "zipfian_int_distribution.h"
|
54 | 54 | * int main()
|
55 | 55 | * {
|
56 | 56 | * std::default_random_engine generator;
|
57 |
| - * zipfian_int_distribution<int>::param_type p(1,1e6, 0.99, 27.000); |
| 57 | + * zipfian_int_distribution<int>::param_type p(1, 1e6, 0.99, 27.000); |
58 | 58 | * zipfian_int_distribution<int> distribution(p);
|
59 | 59 | * int i = distribution(generator);
|
60 | 60 | * }
|
61 | 61 | */
|
62 |
| - |
63 |
| - 0.99 |
64 |
| - max_uint32_t --> 25.4095 |
65 |
| - max_uint64_t --> |
66 | 62 |
|
67 | 63 | #include <cmath>
|
68 | 64 | #include <limits>
|
|
72 | 68 | template<typename _IntType = int>
|
73 | 69 | class zipfian_int_distribution
|
74 | 70 | {
|
75 |
| - static_assert(std::is_integral<_IntType>::value, "template argument not an integral type"); |
| 71 | + static_assert(std::is_integral<_IntType>::value, "Template argument not an integral type."); |
76 | 72 |
|
77 | 73 | public:
|
78 | 74 | /** The type of the range of the distribution. */
|
@@ -122,10 +118,16 @@ class zipfian_int_distribution
|
122 | 118 | double _M_zeta;
|
123 | 119 | double _M_zeta2theta;
|
124 | 120 |
|
125 |
| - double zeta(double n, double theta) |
| 121 | + /** |
| 122 | + * @brief Calculates zeta. |
| 123 | + * |
| 124 | + * @param __n [IN] The size of the domain. |
| 125 | + * @param __theta [IN] The skew factor of the distribution. |
| 126 | + */ |
| 127 | + double zeta(unsigned long __n, double __theta) |
126 | 128 | {
|
127 | 129 | double ans = 0.0;
|
128 |
| - for(int i=1; i<=n; ++i) |
| 130 | + for(unsigned long i=1; i<=n; ++i) |
129 | 131 | ans += std::pow(1.0/i, theta);
|
130 | 132 | return ans;
|
131 | 133 | }
|
|
0 commit comments