Inheritance diagram for SubListGenerator:

Public Member Functions

int *const & get () const override
 
bool next () override
 
 SubListGenerator (Catch::Generators::GeneratorWrapper< int > &&gen, int numSamps, const int *exclude, int numExclude)
 
 SubListGenerator (int *elems, int numElems, int numSamps)
 
 ~SubListGenerator ()
 

Private Member Functions

void createSublist ()
 
void prepareSublist ()
 

Private Attributes

vector< bool > featured
 
int len
 
int * list
 
int sublen
 
int * sublist
 

Detailed Description

Definition at line 1388 of file utilities.cpp.

Constructor & Destructor Documentation

◆ SubListGenerator() [1/2]

SubListGenerator::SubListGenerator ( int *  elems,
int  numElems,
int  numSamps 
)
inline

Definition at line 1417 of file utilities.cpp.

1417  {
1418 
1419  DEMAND( numSamps <= numElems );
1420 
1421  // make a record of all elements
1422  len = numElems;
1423  list = (int*) malloc(len * sizeof *list);
1424  for (int i=0; i<len; i++)
1425  list[i] = elems[i];
1426 
1427  // prepare sublist
1428  sublen = numSamps;
1429  createSublist();
1430  prepareSublist();
1431  }

References createSublist(), DEMAND, len, list, prepareSublist(), and sublen.

◆ SubListGenerator() [2/2]

SubListGenerator::SubListGenerator ( Catch::Generators::GeneratorWrapper< int > &&  gen,
int  numSamps,
const int *  exclude,
int  numExclude 
)
inline

Definition at line 1433 of file utilities.cpp.

1436  {
1437  // extract all generator elems
1438  vector<int> elems = vector<int>();
1439  do { elems.push_back(gen.get()); } while (gen.next());
1440 
1441  // make (int*) of non-excluded elems
1442  len = 0;
1443  list = (int*) malloc(elems.size() * sizeof *list);
1444  for (size_t i=0; i<elems.size(); i++) {
1445  int elem = elems[i];
1446  bool present = false;
1447  for (int j=0; j<numExclude; j++)
1448  if (elem == exclude[j]) {
1449  present = true;
1450  break;
1451  }
1452  if (!present)
1453  list[len++] = elem;
1454  }
1455 
1456  DEMAND( numSamps <= len );
1457 
1458  // prepare sublist
1459  sublen = numSamps;
1460  createSublist();
1461  prepareSublist();
1462  }

References createSublist(), DEMAND, len, list, prepareSublist(), and sublen.

◆ ~SubListGenerator()

SubListGenerator::~SubListGenerator ( )
inline

Definition at line 1483 of file utilities.cpp.

1483  {
1484  free(list);
1485  free(sublist);
1486  }

References list, and sublist.

Member Function Documentation

◆ createSublist()

void SubListGenerator::createSublist ( )
inlineprivate

Definition at line 1395 of file utilities.cpp.

1395  {
1396 
1397  // sublist to send to the user
1398  sublist = (int*) malloc(sublen * sizeof *sublist);
1399 
1400  // indicates which list members are currently in sublist
1401  featured = vector<bool>(len);
1402  fill(featured.end() - sublen, featured.end(), true);
1403  }

References featured, len, sublen, and sublist.

Referenced by SubListGenerator().

◆ get()

int* const& SubListGenerator::get ( ) const
inlineoverride

Definition at line 1464 of file utilities.cpp.

1464  {
1465  return sublist;
1466  }

References sublist.

◆ next()

bool SubListGenerator::next ( )
inlineoverride

Definition at line 1468 of file utilities.cpp.

1468  {
1469 
1470  // offer next permutation of the current combination
1471  if (next_permutation(sublist, sublist+sublen))
1472  return true;
1473 
1474  // else generate the next combination
1475  if (next_permutation(featured.begin(), featured.end())) {
1476  prepareSublist();
1477  return true;
1478  }
1479 
1480  return false;
1481  }

References featured, prepareSublist(), sublen, and sublist.

◆ prepareSublist()

void SubListGenerator::prepareSublist ( )
inlineprivate

Definition at line 1405 of file utilities.cpp.

1405  {
1406 
1407  // choose the next combination
1408  int j=0;
1409  for (int i=0; i<len; i++)
1410  if (featured[i])
1411  sublist[j++] = list[i];
1412 
1413  // prepare for permuting
1414  std::sort(sublist, sublist+sublen);
1415  }

References featured, len, list, sublen, and sublist.

Referenced by next(), and SubListGenerator().

Field Documentation

◆ featured

vector<bool> SubListGenerator::featured
private

Definition at line 1393 of file utilities.cpp.

Referenced by createSublist(), next(), and prepareSublist().

◆ len

int SubListGenerator::len
private

Definition at line 1391 of file utilities.cpp.

Referenced by createSublist(), prepareSublist(), and SubListGenerator().

◆ list

int* SubListGenerator::list
private

Definition at line 1389 of file utilities.cpp.

Referenced by prepareSublist(), SubListGenerator(), and ~SubListGenerator().

◆ sublen

int SubListGenerator::sublen
private

Definition at line 1392 of file utilities.cpp.

Referenced by createSublist(), next(), prepareSublist(), and SubListGenerator().

◆ sublist

int* SubListGenerator::sublist
private

Definition at line 1390 of file utilities.cpp.

Referenced by createSublist(), get(), next(), prepareSublist(), and ~SubListGenerator().


The documentation for this class was generated from the following file:
vector< bool > featured
Definition: utilities.cpp:1393
#define DEMAND(cond)
Definition: utilities.cpp:24