tgen
Loading...
Searching...
No Matches

Permutation instance. More...

Inheritance diagram for tgen::permutation::instance:

Public Member Functions

 instance (const std::vector< int > &vec)
 Creates a permutation instance from a std::vector.
int size () const
 Returns the size of the permutation instance.
const int & operator[] (int idx) const
 Returns the value at some position of the instance.
int parity () const
 Parity of the permutation.
instancesort ()
 Sorts the instance in non-decreasing order.
instancereverse ()
 Reverses the instance.
instanceinverse ()
 Inverse of the permutation.
instanceseparator (char sep)
 Sets separator for printing.
instanceadd_1 ()
 Adds 1 for printing.
std::vector< int > 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

Permutation instance.

Instance of a permutation.

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

Definition at line 1674 of file tgen.h.

Constructor & Destructor Documentation

◆ instance()

tgen::permutation::instance::instance ( const std::vector< int > & vec)
inline

Creates a permutation 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 = {0, 1, 2};
std::cout << inst << std::endl; // Prints "0 1 2".
// Also works with conversions, and std::initializer_list<T>.
inst = {1, 0};
std::cout << inst.add_1() << std::endl; // Prints "2 1".
Permutation instance.
Definition tgen.h:1674

Definition at line 1682 of file tgen.h.

Member Function Documentation

◆ 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

// Prints a 1-based permutation.
tgen::permutation::instance inst = {2, 0, 1};
std::cout << inst.add_1() << std::endl; // Prints "3 1 2".
instance & add_1()
Adds 1 for printing.
Definition tgen.h:1761

Definition at line 1761 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

// Prints inverse of permutation.
tgen::permutation::instance inst = {2, 0, 1};
std::cout << inst.inverse() << std::endl; // Prints "1 2 0".
instance & inverse()
Inverse of the permutation.
Definition tgen.h:1744

Definition at line 1744 of file tgen.h.

◆ operator[]()

const int & tgen::permutation::instance::operator[] ( int idx) const
inline

Returns the value at some position of the instance.

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

Examples

// Prints a position of an instance.
tgen::permutation::instance inst = {2, 0, 1};
std::cout << inst[1] << std::endl; // Prints "0".

Definition at line 1705 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

// Prints parity of permutation.
tgen::permutation::instance inst = {2, 0, 1};
std::cout << inst.parity() << std::endl; // Prints "1".
int parity() const
Parity of the permutation.
Definition tgen.h:1713

Definition at line 1713 of file tgen.h.

◆ reverse()

instance & tgen::permutation::instance::reverse ( )
inline

Reverses the instance.

Complexity

O(n).

Examples

// Reverses and prints an instance.
tgen::permutation::instance inst = {2, 0, 1};
std::cout << inst.reverse() << std::endl; // Prints "1 0 2".
instance & reverse()
Reverses the instance.
Definition tgen.h:1737

Definition at line 1737 of file tgen.h.

◆ separator()

instance & tgen::permutation::instance::separator ( char sep)
inline

Sets separator for printing.

Complexity

O(1).

Examples

// Prints a permutation, separated by commas.
tgen::permutation::instance inst = {2, 0, 1};
std::cout << inst.separator(',') << std::endl; // Prints "2,0,1".
instance & separator(char sep)
Sets separator for printing.
Definition tgen.h:1754

Definition at line 1754 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

// Prints the size of an instance.
tgen::permutation::instance inst = {0, 1, 2};
std::cout << inst.size() << std::endl; // Prints "3".
int size() const
Returns the size of the permutation instance.
Definition tgen.h:1702

Definition at line 1702 of file tgen.h.

◆ sort()

instance & tgen::permutation::instance::sort ( )
inline

Sorts the instance in non-decreasing order.

Complexity

O(n).

Examples

// Sorts and prints an instance.
tgen::permutation::instance inst = {2, 0, 1};
std::cout << inst.sort() << std::endl; // Prints "0 1 2".
instance & sort()
Sorts the instance in non-decreasing order.
Definition tgen.h:1729

Definition at line 1729 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

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

Definition at line 1778 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

// Prints an instance.
std::cout << tgen::permutation::instance({2, 0, 1}) << std::endl; // Prints "2 0 1".

Definition at line 1767 of file tgen.h.


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