CMR  1.3.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
tu::permutation Class Reference

#include <permutations.hpp>

Public Types

typedef size_t size_type
 
typedef ptrdiff_t difference_type
 
typedef size_t value_type
 
typedef std::vector< value_typedata_type
 

Public Member Functions

 permutation (size_type size=0)
 
template<typename RandomNumberGenerator >
 permutation (size_type size, RandomNumberGenerator &rng)
 
 permutation (const permutation &other)
 
virtual ~permutation ()
 
void reset (size_t new_size)
 
void reset ()
 
template<typename RandomNumberGenerator >
void shuffle (RandomNumberGenerator &rng)
 
size_type size () const
 
value_type operator() (value_type index) const
 
value_type get (value_type index) const
 
void swap (value_type a, value_type b)
 
void rswap (value_type a, value_type b)
 
void revert ()
 
permutation reverse () const
 
permutationoperator= (const permutation &other)
 
permutation operator* (const permutation &rhs) const
 
void resize (size_type new_size)
 
void grow (difference_type by)
 
void shrink (difference_type by)
 

Protected Member Functions

void _set (value_type index, value_type value)
 
data_typeget_data ()
 

Protected Attributes

data_type _data
 

Friends

class permutation_enumerator
 Class to enumerate permutations. More...
 
template<class Less >
void sort (permutation &permutation, size_t first, size_t beyond, Less &less)
 Class to setup a permutation which can be put before a vector. More...
 

Detailed Description

A permutation which maps integers from 0 to size-1 to the same range in any possible way. This implementation stores the image of each of the values in a vector.

Member Typedef Documentation

◆ data_type

typedef std::vector<value_type> tu::permutation::data_type

◆ difference_type

◆ size_type

◆ value_type

Constructor & Destructor Documentation

◆ permutation() [1/3]

tu::permutation::permutation ( size_type  size = 0)
inline

Constructs a permutation of a given size, initializing to the identity.

Parameters
sizeOptional size of the permutation

◆ permutation() [2/3]

template<typename RandomNumberGenerator >
tu::permutation::permutation ( size_type  size,
RandomNumberGenerator &  rng 
)
inline

Constructs a permutation of a given size, initializing to a random permutation.

Parameters
sizeOptional size of the permutation
rngRandom number generator.

◆ permutation() [3/3]

tu::permutation::permutation ( const permutation other)
inline

Copy constructor

Parameters
otherAnother permutation

◆ ~permutation()

virtual tu::permutation::~permutation ( )
inlinevirtual

Destructor

Member Function Documentation

◆ _set()

void tu::permutation::_set ( value_type  index,
value_type  value 
)
inlineprotected

Sets a specific value without checking validity.

Parameters
indexIndex of the entry
valueNew value

◆ get()

value_type tu::permutation::get ( value_type  index) const
inline

The image of a specific integer in range 0 .. size-1.

Parameters
indexGiven integer
Returns
The integers image

◆ get_data()

data_type& tu::permutation::get_data ( )
inlineprotected
Returns
A reference to the data vector

◆ grow()

void tu::permutation::grow ( difference_type  by)
inline

Grows the permutation by a given number of elements.

Parameters
byNumber of elements to increase the size by

◆ operator()()

value_type tu::permutation::operator() ( value_type  index) const
inline

The image of a specific integer in range 0 .. size-1.

Parameters
indexGiven integer
Returns
The integers image

◆ operator*()

permutation tu::permutation::operator* ( const permutation rhs) const
inline

Calculates the product of this and another permutation. The result is equivalent to applying the second permutation first and this one afterwards.

Parameters
rhsRight hand side permutation
Returns
The resulting permutation

◆ operator=()

permutation& tu::permutation::operator= ( const permutation other)
inline

Assignment operator.

Parameters
otherAnother permutation
Returns
A reference to this permutation

◆ reset() [1/2]

void tu::permutation::reset ( )
inline

Resets the permutation to identity.

◆ reset() [2/2]

void tu::permutation::reset ( size_t  new_size)
inline

Resizes the permutation and resets it to identity.

Parameters
new_sizeNew size

◆ resize()

void tu::permutation::resize ( size_type  new_size)
inline

Resizes the permutation, retaining the contents. This may fail if it cannot be shrunken this way and will throw a permutation_shrink_exception in that case.

Parameters
new_sizeNew size of the permutation

◆ reverse()

permutation tu::permutation::reverse ( ) const
inline
Returns
The inverse permutation of this permutation

◆ revert()

void tu::permutation::revert ( )
inline

Makes this permutation its own inverse.

Create a temporary copy

◆ rswap()

void tu::permutation::rswap ( value_type  a,
value_type  b 
)
inline

Swaps the preimages of two integers in range 0 .. size-1.

Parameters
aFirst integer
bSecond integer

◆ shrink()

void tu::permutation::shrink ( difference_type  by)
inline

Shrinks the permutation by a given number of elements.

Parameters
byNumber of elements to decrease the size by

◆ shuffle()

template<typename RandomNumberGenerator >
void tu::permutation::shuffle ( RandomNumberGenerator &  rng)
inline

Shuffles a permutation.

Parameters
rngRandom number generator.

◆ size()

size_type tu::permutation::size ( ) const
inline
Returns
The current size of the permutation

◆ swap()

void tu::permutation::swap ( value_type  a,
value_type  b 
)
inline

Swaps the images of two integers in range 0 .. size-1.

Parameters
aFirst integer
bSecond integer

Friends And Related Function Documentation

◆ permutation_enumerator

friend class permutation_enumerator
friend

Class to enumerate permutations.

◆ sort

template<class Less >
void sort ( permutation permutation,
size_t  first,
size_t  beyond,
Less &  less 
)
friend

Class to setup a permutation which can be put before a vector.

Arranges part of a given permutation such that it can be used to view a vector in a sorted way.

Parameters
permutationThe given permutation to be changed
firstFirst index of the part
beyondBeyond index of the part
lessFunctor to compare two elements

Member Data Documentation

◆ _data

data_type tu::permutation::_data
protected

The documentation for this class was generated from the following file: