mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-25 18:40:18 -04:00
Use RND class for shrink_to_rand_elem and add assertions
This commit is contained in:
parent
a9ea8374da
commit
249b75dc29
2 changed files with 6 additions and 6 deletions
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include "rapidhash/rapidhash.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
|
|
@ -57,6 +59,7 @@ RND::rand64(void)
|
|||
u64
|
||||
RND::rand64(cu64 max_)
|
||||
{
|
||||
assert(max_ > 0);
|
||||
return (RND::rand64() % max_);
|
||||
}
|
||||
|
||||
|
|
@ -64,5 +67,6 @@ u64
|
|||
RND::rand64(cu64 min_,
|
||||
cu64 max_)
|
||||
{
|
||||
assert(max_ > min_);
|
||||
return (min_ + (RND::rand64() % (max_ - min_)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include "base_types.h"
|
||||
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
class RND
|
||||
{
|
||||
|
|
@ -38,14 +38,10 @@ public:
|
|||
void
|
||||
shrink_to_rand_elem(std::vector<T> &v_)
|
||||
{
|
||||
static std::mt19937 gen(std::random_device{}());
|
||||
|
||||
if(v_.size() <= 1)
|
||||
return;
|
||||
|
||||
std::uniform_int_distribution<> dist(0,(v_.size() - 1));
|
||||
|
||||
std::swap(v_[0],v_[dist(gen)]);
|
||||
std::swap(v_[0],v_[RND::rand64(v_.size())]);
|
||||
|
||||
v_.resize(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue