tgen
Loading...
Searching...
No Matches
Sequence instances

Instance of a sequence. More...

Classes

struct  tgen::sequence< T >::instance
 Sequence instance. More...

Functions

 tgen::sequence< T >::instance::instance (const std::vector< T > &vec)
 Creates a sequence instance from a std::vector.
int tgen::sequence< T >::instance::size () const
 Returns the size of the sequence instance.
const T & tgen::sequence< T >::instance::operator[] (int idx) const
 Returns the value at some position of the instance.
instancetgen::sequence< T >::instance::sort ()
 Sorts the instance in non-decreasing order.
instancetgen::sequence< T >::instance::reverse ()
 Reverses the instance.
instance tgen::sequence< T >::instance::operator+ (const instance &rhs)
 Concatenates two instances.
std::vector< T > tgen::sequence< T >::instance::to_std () const
 Converts the instance to a std::vector.

Friends

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

Detailed Description

Instance of a sequence.

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

Function 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 conversions, and std::initializer_list<T>.
inst = {5, 4};
std::cout << inst << std::endl; // Prints "5 4".
Sequence instance.
Definition tgen.h:721

Definition at line 727 of file tgen.h.

◆ operator+()

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

Concatenates two instances.

Complexity

Linear.

Examples

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

Definition at line 754 of file tgen.h.

◆ operator[]()

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

Returns the value at some position of the instance.

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

Examples

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

Definition at line 736 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:747

Definition at line 747 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:732

Definition at line 732 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:740

Definition at line 740 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:773

Definition at line 773 of file tgen.h.

Friends

◆ 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 762 of file tgen.h.