tgen
Loading...
Searching...
No Matches

Sequence instance. More...

Inheritance diagram for tgen::sequence< T >::instance:

Public Member Functions

 instance (const std::vector< T > &vec)
 Creates a sequence instance from a std::vector.
int size () const
 Returns the size of the sequence instance.
T & operator[] (int idx)
 Accesses the value at some position of the instance.
instancesort ()
 Sorts the instance in non-decreasing order.
instancereverse ()
 Reverses the instance.
instanceseparator (char sep)
 Sets separator for printing.
instance operator+ (const instance &rhs)
 Concatenates two instances.
std::vector< T > to_std () const
 Converts the instance to a std::vector.
Public Member Functions inherited from tgen::gen_instance_base< instance >
bool operator< (const instance &rhs) const

Friends

std::ostream & operator<< (std::ostream &out, const instance &inst)
 Prints the instance to a std::ostream.

Detailed Description

template<typename T>
struct tgen::sequence< T >::instance

Sequence instance.

Instance of a sequence.

It can be deterministically operated upon (see Generator Instance Operations for random operations) and printed through std::cout.

Definition at line 1242 of file tgen.h.

Constructor & Destructor Documentation

◆ instance()

template<typename T>
tgen::sequence< T >::instance::instance ( const std::vector< T > & vec)
inline

Creates a sequence instance from a std::vector.

Parameters
vecThe std::vector representing the instance.

Examples

// Creates and prints an instance from a std::vector.
std::vector<int> v = {1, 2, 3};
std::cout << inst << std::endl; // Prints "1 2 3".
// Also works with std::initializer_list<T>.
inst = {5, 4};
std::cout << inst << std::endl; // Prints "5 4".
Sequence instance.
Definition tgen.h:1242

Definition at line 1251 of file tgen.h.

Member Function Documentation

◆ operator+()

template<typename T>
instance tgen::sequence< T >::instance::operator+ ( const instance & rhs)
inline

Concatenates two instances.

Parameters
rhsThe right-hand side.
Returns
The concatenation.

Complexity

Linear.

Examples

// Concatenates and prints two instances.
std::cout << s.gen() + s.gen() << std::endl;
Sequence generator.
Definition tgen.h:1135
sequence & distinct(std::set< int > indices)
Restricts generator s.t. all values in index set are distinct.
Definition tgen.h:1221
instance gen() const
Generates a random instance from the set of valid sequences.
Definition tgen.h:1367

Definition at line 1293 of file tgen.h.

◆ operator[]()

template<typename T>
T & tgen::sequence< T >::instance::operator[] ( int idx)
inline

Accesses the value at some position of the instance.

Parameters
idxIndex to be accessed.
Returns
The value at index idx.

Examples

// Changes and prints a position of an instance.
++inst[1];
std::cout << inst[1] << std::endl; // Prints "3".

Definition at line 1259 of file tgen.h.

◆ reverse()

template<typename T>
instance & tgen::sequence< T >::instance::reverse ( )
inline

Reverses the instance.

Complexity

O(n).

Examples

// Reverses and prints an instance.
std::cout << inst.reverse() << std::endl; // Prints "2 1 3".
instance & reverse()
Reverses the instance.
Definition tgen.h:1279

Definition at line 1279 of file tgen.h.

◆ separator()

template<typename T>
instance & tgen::sequence< T >::instance::separator ( char sep)
inline

Sets separator for printing.

Complexity

O(1).

Examples

// Prints an instance, separated by commas.
std::cout << inst.separator(',') << std::endl; // Prints "3,1,2".
instance & separator(char sep)
Sets separator for printing.
Definition tgen.h:1286

Definition at line 1286 of file tgen.h.

◆ size()

template<typename T>
int tgen::sequence< T >::instance::size ( ) const
inline

Returns the size of the sequence instance.

Returns
The size (number of elements) of the sequence instance.

Examples

// Prints the size of an instance.
std::cout << inst.size() << std::endl; // Prints "3".
int size() const
Returns the size of the sequence instance.
Definition tgen.h:1256

Definition at line 1256 of file tgen.h.

◆ sort()

template<typename T>
instance & tgen::sequence< T >::instance::sort ( )
inline

Sorts the instance in non-decreasing order.

Complexity

O(n log n).

Examples

// Sorts and prints an instance.
std::cout << inst.sort() << std::endl; // Prints "1 2 3".
instance & sort()
Sorts the instance in non-decreasing order.
Definition tgen.h:1272

Definition at line 1272 of file tgen.h.

◆ to_std()

template<typename T>
std::vector< T > tgen::sequence< T >::instance::to_std ( ) const
inline

Converts the instance to a std::vector.

Returns
A std::vector representing the instance.

Examples

// Convoluted way to reverse a vector.
std::vector<int> v = {3, 1, 2};
// v = {2, 1, 3}.
std::vector< T > to_std() const
Converts the instance to a std::vector.
Definition tgen.h:1312

Definition at line 1312 of file tgen.h.

◆ operator<<

template<typename T>
std::ostream & operator<< ( std::ostream & out,
const instance & inst )
friend

Prints the instance to a std::ostream.

The values are printed with one space as a separator, and with no end of line.

Examples

// Prints an instance.
std::cout << tgen::sequence<int>::instance({3, 1, 2}) << std::endl; // Prints "3 1 2".

Definition at line 1301 of file tgen.h.


The documentation for this struct was generated from the following files:
  • /home/runner/work/tgen/tgen/single_include/tgen.h
  • sequence.dox