diff --git a/Helper_8h_source.html b/Helper_8h_source.html index e0d0fa008..b414fddef 100644 --- a/Helper_8h_source.html +++ b/Helper_8h_source.html @@ -192,86 +192,83 @@
132 throw std::invalid_argument{"Sum of weights is zero."};
133 }
134
-
135 const std::integral auto targetWeightValue = Number::integer<unsigned>(sumOfWeights);
-
136
-
137 unsigned currentSum = 0;
+
135 const std::integral auto targetWeightValue = Number::integer<unsigned>(1, sumOfWeights);
+
136 unsigned currentSum = 0;
+
137 size_t currentIdx = 0;
138
-
139 for (const auto& element : data)
-
140 {
-
141 currentSum += element.weight;
-
142
-
143 if (targetWeightValue <= currentSum)
-
144 {
-
145 return element.value;
-
146 }
-
147 }
+
139 while (currentIdx < data.size()) {
+
140 currentSum += data[currentIdx].weight;
+
141 if (currentSum >= targetWeightValue)
+
142 break;
+
143 currentIdx++;
+
144 }
+
145
+
146 return data.at(currentIdx).value;
+
147 }
+
148
-
149 return data.at(data.size() - 1).value;
-
150 }
+
162 template <class T>
+
+
163 static std::vector<T> shuffle(std::vector<T> data)
+
164 {
+
165 std::shuffle(std::begin(data), std::end(data), pseudoRandomGenerator);
+
166
+
167 return data;
+
168 }
-
151
-
165 template <class T>
-
-
166 static std::vector<T> shuffle(std::vector<T> data)
-
167 {
-
168 std::shuffle(std::begin(data), std::end(data), pseudoRandomGenerator);
169
-
170 return data;
-
171 }
+
181 static std::string shuffleString(std::string data);
+
182
+
203 template <typename T>
+
+
204 static typename T::key_type objectKey(const T& object)
+
205 {
+
206 if (object.empty())
+
207 {
+
208 throw std::runtime_error("Object is empty.");
+
209 }
+
210
+
211 std::vector<typename T::key_type> keys;
+
212 for (const auto& entry : object)
+
213 {
+
214 keys.push_back(entry.first);
+
215 }
+
216
+
217 return arrayElement<typename T::key_type>(keys);
+
218 }
-
172
-
184 static std::string shuffleString(std::string data);
-
185
-
206 template <typename T>
-
-
207 static typename T::key_type objectKey(const T& object)
-
208 {
-
209 if (object.empty())
-
210 {
-
211 throw std::runtime_error("Object is empty.");
-
212 }
-
213
-
214 std::vector<typename T::key_type> keys;
-
215 for (const auto& entry : object)
-
216 {
-
217 keys.push_back(entry.first);
-
218 }
219
-
220 return arrayElement<typename T::key_type>(keys);
-
221 }
-
-
222
-
239 template <typename TResult>
-
-
240 static TResult maybe(std::function<TResult()> callback, double probability = 0.5)
-
241 {
-
242 if (Datatype::boolean(probability))
-
243 {
-
244 return callback();
-
245 }
-
246 return TResult();
-
247 }
+
236 template <typename TResult>
+
+
237 static TResult maybe(std::function<TResult()> callback, double probability = 0.5)
+
238 {
+
239 if (Datatype::boolean(probability))
+
240 {
+
241 return callback();
+
242 }
+
243 return TResult();
+
244 }
-
248
-
265 static std::string replaceSymbolWithNumber(const std::string& str, const char& symbol = '#');
-
266
-
282 static std::string replaceCreditCardSymbols(const std::string& inputString = "6453-####-####-####-###L",
-
283 char symbol = '#');
-
284
-
305 static std::string regexpStyleStringParse(const std::string& input);
-
306
-
307private:
-
308 static std::random_device randomDevice;
-
309 static std::mt19937 pseudoRandomGenerator;
-
310};
+
245
+
262 static std::string replaceSymbolWithNumber(const std::string& str, const char& symbol = '#');
+
263
+
279 static std::string replaceCreditCardSymbols(const std::string& inputString = "6453-####-####-####-###L",
+
280 char symbol = '#');
+
281
+
302 static std::string regexpStyleStringParse(const std::string& input);
+
303
+
304private:
+
305 static std::random_device randomDevice;
+
306 static std::mt19937 pseudoRandomGenerator;
+
307};
-
311}
+
308}
static bool boolean()
Returns a random boolean.
Definition Helper.h:16
-
static T::key_type objectKey(const T &object)
Returns a random key from given object.
Definition Helper.h:207
-
static TResult maybe(std::function< TResult()> callback, double probability=0.5)
Returns the result of the callback if the probability check was successful, otherwise empty string.
Definition Helper.h:240
+
static T::key_type objectKey(const T &object)
Returns a random key from given object.
Definition Helper.h:204
+
static TResult maybe(std::function< TResult()> callback, double probability=0.5)
Returns the result of the callback if the probability check was successful, otherwise empty string.
Definition Helper.h:237
static T arrayElement(std::span< const T > data)
Get a random element from an STL container.
Definition Helper.h:33
-
static std::vector< T > shuffle(std::vector< T > data)
Returns shuffled vector.
Definition Helper.h:166
+
static std::vector< T > shuffle(std::vector< T > data)
Returns shuffled vector.
Definition Helper.h:163
static T weightedArrayElement(const std::vector< WeightedElement< T > > &data)
Get a random element by weight from a vector.
Definition Helper.h:119
static std::string replaceCreditCardSymbols(const std::string &inputString="6453-####-####-####-###L", char symbol='#')
Returns credit card schema with replaced symbols and patterns in a credit card including Luhn checksu...
static std::string shuffleString(std::string data)
Returns shuffled std::string.
diff --git a/classfaker_1_1Helper.html b/classfaker_1_1Helper.html index b7a4c3abb..7be02c3f1 100644 --- a/classfaker_1_1Helper.html +++ b/classfaker_1_1Helper.html @@ -339,7 +339,7 @@

{3, "three"}

};
Helper::objectKey(testMap) // "2"
-
faker::Helper::objectKey
static T::key_type objectKey(const T &object)
Returns a random key from given object.
Definition Helper.h:207
+
faker::Helper::objectKey
static T::key_type objectKey(const T &object)
Returns a random key from given object.
Definition Helper.h:204
diff --git a/doxygen-awesome.css b/doxygen-awesome.css index ac7f0608e..a11ceab33 100644 --- a/doxygen-awesome.css +++ b/doxygen-awesome.css @@ -313,7 +313,7 @@ body { body, table, div, p, dl, #nav-tree .label, .title, .sm-dox a, .sm-dox a:hover, .sm-dox a:focus, #projectname, .SelectItem, #MSearchField, .navpath li.navelem a, -.navpath li.navelem a:hover, p.reference, p.definition { +.navpath li.navelem a:hover, p.reference, p.definition, div.toc li, div.toc h3 { font-family: var(--font-family); } @@ -2460,17 +2460,17 @@ h2:hover a.anchorlink, h1:hover a.anchorlink, h3:hover a.anchorlink, h4:hover a. Optional tab feature */ -.tabbed ul { +.tabbed > ul { padding-inline-start: 0px; margin: 0; padding: var(--spacing-small) 0; } -.tabbed li { +.tabbed > ul > li { display: none; } -.tabbed li.selected { +.tabbed > ul > li.selected { display: block; }