tgen
Loading...
Searching...
No Matches
Generator Instance Operations

Operations for tgen generator instances. More...

Collaboration diagram for Generator Instance Operations:

Functions

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
void tgen::shuffle (Inst &inst)
 Shuffles a sequence instance.
template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst tgen::shuffled (const Inst &inst)
 Shuffles a sequence instance.
template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst::value_type tgen::any (const Inst &inst)
 Choses a random element from the sequence instance.
template<typename Inst, typename T, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst::value_type tgen::any_by_distribution (const Inst &inst, const std::vector< T > &distribution)
 Choses a random element from the sequence instance.
template<typename Inst, std::enable_if_t< is_sequential< Inst >::value and has_subset_defined< Inst >::value, int > = 0>
Inst tgen::choose (int k, const Inst &inst)
 Chooses some values from the sequence instance, as in a subsequence of fixed length.

Detailed Description

Operations for tgen generator instances.

Examples

Function Documentation

◆ any()

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst::value_type tgen::any ( const Inst & inst)

Choses a random element from the sequence instance.

Template Parameters
InstSequence instance type, deduced automatically. Must be a tgen::sequence::instance.
Parameters
instThe original instance.
Returns
A uniformly random element from the instance.

Complexity

O(1).

Examples

// Prints a random element from v.
std::cout << tgen::any(inst) << std::endl;
It::value_type any(It first, It last)
Choses a random element from iterator range.
Definition tgen.h:624
Sequence instance.
Definition tgen.h:1242

Definition at line 645 of file tgen.h.

◆ any_by_distribution()

template<typename Inst, typename T, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst::value_type tgen::any_by_distribution ( const Inst & inst,
const std::vector< T > & distribution )

Choses a random element from the sequence instance.

Template Parameters
InstSequence instance type, deduced automatically. Must be a tgen::sequence::instance.
Parameters
instThe instance to choose from.
distributionThe probability distribution.
Returns
A uniformly random element from the instance.

Complexity

O(1).

Examples

// Prints a random element from instance with given odds.
std::cout << tgen::any_by_distribution(inst, {1, 2, 3}) << std::endl;
C::value_type any_by_distribution(const C &container, std::vector< T > distribution)
Choses a random element with given probabilities.
Definition tgen.h:653

Definition at line 685 of file tgen.h.

◆ choose()

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value and has_subset_defined< Inst >::value, int > = 0>
Inst tgen::choose ( int k,
const Inst & inst )

Chooses some values from the sequence instance, as in a subsequence of fixed length.

Template Parameters
InstSequence instance type, deduced automatically. Must be a tgen::sequence::instance.
Parameters
kThe size of the subsequence.
instThe original instance.
Returns
A uniformly random subsequence of length k.

Complexity

O(|inst|).

Examples

// Prints a subsequenec of length 2 from v.
std::cout << tgen::choose(2, inst) << std::endl;
C choose(int k, const C &container)
Chooses elements from container, as in a subsequence fixed length.
Definition tgen.h:702

Definition at line 727 of file tgen.h.

◆ shuffle()

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
void tgen::shuffle ( Inst & inst)

Shuffles a sequence instance.

Template Parameters
InstSequence instance type, deduced automatically. Must be a tgen::sequence::instance.
Parameters
instThe instance to shuffle.

Complexity

O(|inst|).

Examples

// Shuffles and prints an instance.
void shuffle(It first, It last)
Shuffles range inplace, for random_access_iterator.
Definition tgen.h:576

Definition at line 587 of file tgen.h.

◆ shuffled()

template<typename Inst, std::enable_if_t< is_sequential< Inst >::value, int > = 0>
Inst tgen::shuffled ( const Inst & inst)
nodiscard

Shuffles a sequence instance.

Template Parameters
InstSequence instance type, deduced automatically. Must be a tgen::sequence::instance.
Parameters
instThe original instance.
Returns
The shuffled instance.

Complexity

O(|inst|).

Examples

// Shuffles and prints an instance.
std::cout << tgen::shuffled(inst) << std::endl;
C shuffled(const C &container)
Shuffles a container.
Definition tgen.h:597

Definition at line 616 of file tgen.h.