Instance of a permutation.
More...
Instance of a permutation.
It can be deterministically operated upon and printed through std::cout.
◆ add_1()
| instance & tgen::permutation::instance::add_1 |
( |
| ) |
|
|
inline |
Adds 1 for printing.
This makes it so, when given to std::cout, the permutation will be printed as 1-based.
Complexity
O(1).
Examples
std::cout <<
inst.
add_1() << std::endl;
instance & add_1()
Adds 1 for printing.
Definition at line 1191 of file tgen.h.
◆ instance()
| tgen::permutation::instance::instance |
( |
const std::vector< int > & | vec | ) |
|
|
inline |
Creates a permutation instance from a std::vector.
- Parameters
-
| vec | The std::vector representing the instance. |
Examples
std::vector<int> v = {0, 1, 2};
std::cout << inst << std::endl;
inst = {1, 0};
std::cout << inst.add_1() << std::endl;
Definition at line 1126 of file tgen.h.
◆ inverse()
| instance & tgen::permutation::instance::inverse |
( |
| ) |
|
|
inline |
Inverse of the permutation.
The inverse of the permutation p is another pi such that pi[p[i]] = p[pi[i]] = i.
Complexity
O(n).
Examples
std::cout <<
instance & inverse()
Inverse of the permutation.
Definition at line 1181 of file tgen.h.
◆ operator[]()
| int & tgen::permutation::instance::operator[] |
( |
int | idx | ) |
|
|
inline |
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 1145 of file tgen.h.
◆ parity()
| int tgen::permutation::instance::parity |
( |
| ) |
const |
|
inline |
Parity of the permutation.
- Returns
- +1 if the permutation is even, or -1 if the permutation is odd.
Examples
std::cout <<
int parity() const
Parity of the permutation.
Definition at line 1150 of file tgen.h.
◆ reverse()
| instance & tgen::permutation::instance::reverse |
( |
| ) |
|
|
inline |
Reverses the instance.
Complexity
O(n).
Examples
std::cout <<
instance & reverse()
Reverses the instance.
Definition at line 1174 of file tgen.h.
◆ size()
| int tgen::permutation::instance::size |
( |
| ) |
const |
|
inline |
Returns the size of the permutation instance.
- Returns
- The size (number of elements) of the permutation instance.
Examples
std::cout <<
inst.
size() << std::endl;
int size() const
Returns the size of the permutation instance.
Definition at line 1142 of file tgen.h.
◆ sort()
| instance & tgen::permutation::instance::sort |
( |
| ) |
|
|
inline |
Sorts the instance in non-decreasing order.
Complexity
O(n).
Examples
std::cout <<
inst.
sort() << std::endl;
instance & sort()
Sorts the instance in non-decreasing order.
Definition at line 1166 of file tgen.h.
◆ to_std()
| std::vector< int > tgen::permutation::instance::to_std |
( |
| ) |
const |
|
inline |
Converts the instance to a std::vector.
- Returns
- A std::vector representing the instance.
Examples
std::vector<int> v = {2, 0, 1};
std::vector< int > to_std() const
Converts the instance to a std::vector.
Definition at line 1208 of file tgen.h.
◆ operator<<
| 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 1197 of file tgen.h.