Instance of a sequence.
More...
Instance of a sequence.
It can be deterministically operated upon (see Sequence operations for random operations) and printed through std::cout.
◆ instance()
template<typename T>
| tgen::sequence< T >::instance::instance |
( |
const std::vector< T > & | vec | ) |
|
|
inline |
Creates a sequence instance from a std::vector.
- Parameters
-
| vec | The std::vector representing the instance. |
Examples
std::vector<int> v = {1, 2, 3};
std::cout << inst << std::endl;
inst = {5, 4};
std::cout << inst << std::endl;
Definition at line 727 of file tgen.h.
◆ operator+()
Concatenates two instances.
Complexity
Linear.
Examples
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.
instance gen() const
Generates a random instance from the set of valid sequences.
Definition at line 754 of file tgen.h.
◆ operator[]()
Returns the value at some position of the instance.
- Parameters
-
| idx | The index to be accessed. |
- Returns
- The value at index idx.
Examples
++inst[1];
std::cout << inst[1] << std::endl;
Definition at line 736 of file tgen.h.
◆ reverse()
Reverses the instance.
Complexity
O(n).
Examples
std::cout <<
instance & reverse()
Reverses the instance.
Definition at line 747 of file tgen.h.
◆ size()
Returns the size of the sequence instance.
- Returns
- The size (number of elements) of the sequence instance.
Examples
std::cout <<
inst.
size() << std::endl;
int size() const
Returns the size of the sequence instance.
Definition at line 732 of file tgen.h.
◆ sort()
Sorts the instance in non-decreasing order.
Complexity
O(n log n).
Examples
std::cout <<
inst.
sort() << std::endl;
instance & sort()
Sorts the instance in non-decreasing order.
Definition at line 740 of file tgen.h.
◆ to_std()
Converts the instance to a std::vector.
- Returns
- A std::vector representing the instance.
Examples
std::vector<int> v = {3, 1, 2};
std::vector< T > to_std() const
Converts the instance to a std::vector.
Definition at line 773 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
Definition at line 762 of file tgen.h.