aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/Utilities/Containers.h24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h
index df97e342932..5d16576baf2 100644
--- a/src/common/Utilities/Containers.h
+++ b/src/common/Utilities/Containers.h
@@ -74,34 +74,34 @@ namespace Trinity
* Select a random element from a container where each element has a different chance to be selected.
*
* @param container Container to select an element from
- * @param weightExtractor Function retrieving chance of each element in container
+ * @param weights Chances of each element to be selected, must be in the same order as elements in container
*
* Note: container cannot be empty
*/
template <class C>
- typename C::const_iterator SelectRandomWeightedContainerElement(C const& container, std::function<double(typename C::value_type const&)> weightExtractor)
+ typename C::const_iterator SelectRandomWeightedContainerElement(C const& container, std::vector<double> weights)
{
- std::vector<double> weights;
- weights.reserve(container.size());
- std::transform(container.begin(), container.end(), std::back_inserter(weights), weightExtractor);
- return SelectRandomWeightedContainerElement(container, weights);
+ std::discrete_distribution<uint32> dd(weights.begin(), weights.end());
+ typename C::const_iterator it = container.begin();
+ std::advance(it, dd(SFMTEngine::Instance()));
+ return it;
}
/*
* Select a random element from a container where each element has a different chance to be selected.
*
* @param container Container to select an element from
- * @param weights Chances of each element to be selected, must be in the same order as elements in container
+ * @param weightExtractor Function retrieving chance of each element in container
*
* Note: container cannot be empty
*/
template <class C>
- typename C::const_iterator SelectRandomWeightedContainerElement(C const& container, std::vector<double> weights)
+ typename C::const_iterator SelectRandomWeightedContainerElement(C const& container, std::function<double(typename C::value_type const&)> weightExtractor)
{
- std::discrete_distribution<uint32> dd(weights.begin(), weights.end());
- typename C::const_iterator it = container.begin();
- std::advance(it, dd(SFMTEngine::Instance()));
- return it;
+ std::vector<double> weights;
+ weights.reserve(container.size());
+ std::transform(container.begin(), container.end(), std::back_inserter(weights), weightExtractor);
+ return SelectRandomWeightedContainerElement(container, weights);
}
/**