[+] IRandomDevice::ShuffleIterators

[+] IRandomDevice::ShuffleList
[+] AuRNG::RngShuffleIterators
[+] AuRNG::RngShuffleList
This commit is contained in:
Reece Wilson 2024-02-25 19:29:06 +00:00
parent b07db2a2c9
commit 8c101cea6f
2 changed files with 52 additions and 4 deletions

View File

@ -103,16 +103,40 @@ namespace Aurora::RNG
}
template<typename T>
inline T &NextVector(AuList<T> &items)
inline T &NextList(AuList<T> &items)
{
return *NextRange(items);
}
template<typename T>
inline const T &NextVector(const AuList<T> &items)
inline const T &NextList(const AuList<T> &items)
{
return *NextRange(items);
}
template<typename T>
inline void ShuffleIterators(T begin, T end)
{
AU_DEBUG_MEMCRUNCH;
auto uCount = std::distance(begin, end);
auto nextIndexArray = this->NextArrayU32Range(uCount, 0, uCount - 1);
for (AU_ITERATE_N(i, AuUInt(uCount)))
{
auto nextItrA = begin;
auto nextItrB = begin;
std::advance(nextItrA, i);
std::advance(nextItrB, nextIndexArray[i]);
AuSwap(*nextItrA, *nextItrB);
}
}
template<typename T>
inline void ShuffleList(AuList<T> &list)
{
this->ShuffleIterators(list.begin(), list.end());
}
};
AUKN_SHARED_SOO2(Random, IRandomDevice, kSizeRNGDevice,

View File

@ -124,14 +124,38 @@ namespace Aurora::RNG
}
template<typename T>
static auline T &RngVector(AuList<T> &items)
static auline T &RngList(AuList<T> &items)
{
return *RngRange(items);
}
template<typename T>
static auline const T &RngVector(const AuList<T> &items)
static auline const T &RngList(const AuList<T> &items)
{
return *RngRange(items);
}
template<typename T>
inline void RngShuffleIterators(T begin, T end)
{
AU_DEBUG_MEMCRUNCH;
auto uCount = std::distance(begin, end);
auto nextIndexArray = RngArrayU32Range(uCount, 0, uCount - 1);
for (AU_ITERATE_N(i, AuUInt(uCount)))
{
auto nextItrA = begin;
auto nextItrB = begin;
std::advance(nextItrA, i);
std::advance(nextItrB, nextIndexArray[i]);
AuSwap(*nextItrA, *nextItrB);
}
}
template<typename T>
inline void RngShuffleList(AuList<T> &list)
{
RngShuffleIterators(list.begin(), list.end());
}
}