proxygen
folly::test::UniformSubset Struct Reference

Public Member Functions

 UniformSubset (uint64_t seed, size_t subsetSize, size_t stepsBetweenSelect)
 
size_t operator() (size_t numActive)
 

Private Member Functions

void adjustPermSize (size_t numActive)
 
void shufflePrefix ()
 

Private Attributes

std::function< size_t(size_t)> uniform_
 
const size_t subsetSize_
 
const size_t stepsBetweenSelect_
 
size_t stepsLeft_
 
std::vector< size_t > perm_
 

Detailed Description

Definition at line 76 of file DeterministicSchedule.cpp.

Constructor & Destructor Documentation

folly::test::UniformSubset::UniformSubset ( uint64_t  seed,
size_t  subsetSize,
size_t  stepsBetweenSelect 
)
inline

Definition at line 77 of file DeterministicSchedule.cpp.

79  subsetSize_(subsetSize),
80  stepsBetweenSelect_(stepsBetweenSelect),
81  stepsLeft_(0) {}
static const int seed
static std::function< size_t(size_t)> uniform(uint64_t seed)
std::function< size_t(size_t)> uniform_

Member Function Documentation

void folly::test::UniformSubset::adjustPermSize ( size_t  numActive)
inlineprivate

Definition at line 101 of file DeterministicSchedule.cpp.

References x.

101  {
102  if (perm_.size() > numActive) {
103  perm_.erase(
104  std::remove_if(
105  perm_.begin(),
106  perm_.end(),
107  [=](size_t x) { return x >= numActive; }),
108  perm_.end());
109  } else {
110  while (perm_.size() < numActive) {
111  perm_.push_back(perm_.size());
112  }
113  }
114  assert(perm_.size() == numActive);
115  }
Definition: InvokeTest.cpp:58
const int x
size_t folly::test::UniformSubset::operator() ( size_t  numActive)
inline

Definition at line 83 of file DeterministicSchedule.cpp.

References min.

83  {
84  adjustPermSize(numActive);
85  if (stepsLeft_-- == 0) {
87  shufflePrefix();
88  }
89  return perm_[uniform_(std::min(numActive, subsetSize_))];
90  }
LogLevel min
Definition: LogLevel.cpp:30
std::function< size_t(size_t)> uniform_
void adjustPermSize(size_t numActive)
void folly::test::UniformSubset::shufflePrefix ( )
inlineprivate

Definition at line 117 of file DeterministicSchedule.cpp.

References i, min, and folly::f14::swap().

117  {
118  for (size_t i = 0; i < std::min(perm_.size() - 1, subsetSize_); ++i) {
119  size_t j = uniform_(perm_.size() - i) + i;
120  std::swap(perm_[i], perm_[j]);
121  }
122  }
LogLevel min
Definition: LogLevel.cpp:30
std::function< size_t(size_t)> uniform_
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414

Member Data Documentation

std::vector<size_t> folly::test::UniformSubset::perm_
private

Definition at line 99 of file DeterministicSchedule.cpp.

const size_t folly::test::UniformSubset::stepsBetweenSelect_
private

Definition at line 95 of file DeterministicSchedule.cpp.

size_t folly::test::UniformSubset::stepsLeft_
private

Definition at line 97 of file DeterministicSchedule.cpp.

const size_t folly::test::UniformSubset::subsetSize_
private

Definition at line 94 of file DeterministicSchedule.cpp.

std::function<size_t(size_t)> folly::test::UniformSubset::uniform_
private

Definition at line 93 of file DeterministicSchedule.cpp.


The documentation for this struct was generated from the following file: