TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Trinity::Containers Namespace Reference

Functions

template<class T >
void RandomResizeList (std::list< T > &list, uint32 size)
 
template<class T , class Predicate >
void RandomResizeList (std::list< T > &list, Predicate &predicate, uint32 size)
 
template<class C >
C::value_type constSelectRandomContainerElement (C const &container)
 
template<class C >
C::const_iterator SelectRandomWeightedContainerElement (C const &container, std::vector< double > weights)
 
template<class C , class Fn >
C::const_iterator SelectRandomWeightedContainerElement (C const &container, Fn weightExtractor)
 
template<class Iterator1 , class Iterator2 >
bool Intersects (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2)
 
template<class K , class V , template< class, class, class...> class M, class... Rest>
void MultimapErasePair (M< K, V, Rest...> &multimap, K const &key, V const &value)
 

Function Documentation

template<class Iterator1 , class Iterator2 >
bool Trinity::Containers::Intersects ( Iterator1  first1,
Iterator1  last1,
Iterator2  first2,
Iterator2  last2 
)
134  {
135  while (first1 != last1 && first2 != last2)
136  {
137  if (*first1 < *first2)
138  ++first1;
139  else if (*first2 < *first1)
140  ++first2;
141  else
142  return true;
143  }
144 
145  return false;
146  }

+ Here is the caller graph for this function:

template<class K , class V , template< class, class, class...> class M, class... Rest>
void Trinity::Containers::MultimapErasePair ( M< K, V, Rest...> &  multimap,
K const key,
V const value 
)
150  {
151  auto range = multimap.equal_range(key);
152  for (auto itr = range.first; itr != range.second;)
153  {
154  if (itr->second == value)
155  itr = multimap.erase(itr);
156  else
157  ++itr;
158  }
159  }
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the caller graph for this function:

template<class T >
void Trinity::Containers::RandomResizeList ( std::list< T > &  list,
uint32  size 
)
35  {
36  uint32 list_size = uint32(list.size());
37 
38  while (list_size > size)
39  {
40  typename std::list<T>::iterator itr = list.begin();
41  std::advance(itr, urand(0, list_size - 1));
42  list.erase(itr);
43  --list_size;
44  }
45  }
void advance(octet_iterator &it, distance_type n, octet_iterator end)
Definition: checked.h:190
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
uint32_t uint32
Definition: Define.h:150
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class Predicate >
void Trinity::Containers::RandomResizeList ( std::list< T > &  list,
Predicate &  predicate,
uint32  size 
)

First use predicate filter

49  {
51  std::list<T> listCopy;
52  for (typename std::list<T>::iterator itr = list.begin(); itr != list.end(); ++itr)
53  if (predicate(*itr))
54  listCopy.push_back(*itr);
55 
56  if (size)
57  RandomResizeList(listCopy, size);
58 
59  list = listCopy;
60  }
void RandomResizeList(std::list< T > &list, Predicate &predicate, uint32 size)
Definition: Containers.h:48

+ Here is the call graph for this function:

template<class C >
C::value_type const& Trinity::Containers::SelectRandomContainerElement ( C const container)
69  {
70  typename C::const_iterator it = container.begin();
71  std::advance(it, urand(0, uint32(container.size()) - 1));
72  return *it;
73  }
void advance(octet_iterator &it, distance_type n, octet_iterator end)
Definition: checked.h:190
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

template<class C >
C::const_iterator Trinity::Containers::SelectRandomWeightedContainerElement ( C const container,
std::vector< double >  weights 
)
86  {
87  Trinity::discrete_distribution_param<uint32> ddParam(weights.begin(), weights.end());
88  std::discrete_distribution<uint32> dd(ddParam);
89  typename C::const_iterator it = container.begin();
91  return it;
92  }
void advance(octet_iterator &it, distance_type n, octet_iterator end)
Definition: checked.h:190
static SFMTEngine & Instance()
Definition: Random.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class C , class Fn >
C::const_iterator Trinity::Containers::SelectRandomWeightedContainerElement ( C const container,
Fn  weightExtractor 
)
104  {
105  std::vector<double> weights;
106  weights.reserve(container.size());
107  double weightSum = 0.0;
108  for (auto itr = container.begin(); itr != container.end(); ++itr)
109  {
110  double weight = weightExtractor(*itr);
111  weights.push_back(weight);
112  weightSum += weight;
113  }
114  if (weightSum <= 0.0)
115  weights.assign(container.size(), 1.0);
116 
117  return SelectRandomWeightedContainerElement(container, weights);
118  }
C::const_iterator SelectRandomWeightedContainerElement(C const &container, Fn weightExtractor)
Definition: Containers.h:103

+ Here is the call graph for this function: