Cayley
Pseudo-Random Bits from Finite Groups
Public Member Functions | Public Attributes | Private Attributes | Friends | List of all members
CPerm Class Reference

Permutation. More...

#include <Permutation.h>

Public Member Functions

 CPerm (uint8_t n)
 Constructor. More...
 
 CPerm (uint8_t n, uintx_t m)
 Constructor. More...
 
 CPerm (uint8_t n, uint8_t init[])
 Constructor. More...
 
 CPerm (const CPerm &p)
 Copy constructor. More...
 
 ~CPerm ()
 Destructor. More...
 
void Randomize (uint64_t(*rng)(void))
 Set to random permutation. More...
 
void RandomizeOdd (uint64_t(*rng)(void))
 Set to random odd permutation. More...
 
void Randomize (uint32_t s[])
 Set to random permutation. More...
 
uint8_t GetSize () const
 Get size. More...
 
bool IsIdentity () const
 Identity permutation test. More...
 
void printmap () const
 Print as a map. More...
 
void printnum () const
 Print reverse lexicographic number. More...
 
template<class uint >
uint GetNum () const
 Get reverse lexicographic number. More...
 
uint8_t operator[] (uint8_t n) const
 Get nth element of map. More...
 
CPermoperator= (const CPerm &p)
 Assignment operator. More...
 
const CPermoperator *= (const CPerm &p)
 Permutation composition. More...
 

Public Attributes

std::vector< uint8_t > m_vecCycle
 Cycle notation.
 

Private Attributes

uint8_t * m_nMap
 Permutation sends i to m_nMap[i].
 
uint8_t m_nSize
 Number of things being permuted.
 

Friends

bool operator== (const CPerm &p0, const CPerm &p1)
 Equality test. More...
 

Detailed Description

A permutation that can be created from an array, from a reverse lexicographic number or pseudorandomly using a PRNG. Functionality includes permutation composition and calculating its reverse lexicographic number. Permutations can have size at most 256 since it uses a table of 8-bit unsigned integers in order to improve caching by decreasing its memory footprint.

Definition at line 20 of file Permutation.h.

Constructor & Destructor Documentation

◆ CPerm() [1/4]

CPerm::CPerm ( uint8_t  n)

Construct the identity permutation, that is, the permutation that maps everything to itself.

Parameters
nSize of permutation.

Definition at line 17 of file Permutation.cpp.

◆ CPerm() [2/4]

CPerm::CPerm ( uint8_t  n,
uintx_t  m 
)

Use the method of Hall and Knuth, "Combinatorial analysis and computers", The American Mathematical Monthly 72(2):21-28, 1965, to construct a permutation from its reverse lexicographic number using mixed-radix arithmetic. This is the inverse of operator uintx_t().

Parameters
nSize of permutation.
mReverse lexicographic number of permutation.

Definition at line 31 of file Permutation.cpp.

◆ CPerm() [3/4]

CPerm::CPerm ( uint8_t  n,
uint8_t  init[] 
)

Construct a permutation from a permutation table. It is assumed that the permutation table has the right size and does indeed describe a permutation.

Parameters
nSize of permutation.
initPermutation table.

Definition at line 76 of file Permutation.cpp.

◆ CPerm() [4/4]

CPerm::CPerm ( const CPerm p)

Construct a deep copy of a permutation.

Parameters
pThe permutation to copy from.

Definition at line 84 of file Permutation.cpp.

◆ ~CPerm()

CPerm::~CPerm ( )

The destructor.

Definition at line 91 of file Permutation.cpp.

Member Function Documentation

◆ GetNum()

template<class uint >
template uint8_t CPerm::GetNum< uint8_t > ( ) const

Use the method of Hall and Knuth, "Combinatorial analysis and computers", The American Mathematical Monthly 72(2):21-28, 1965, to compute the index of the permutation in reverse lexicographic order using mixed-radix arithmetic. This is the inverse of the constructor CPerm(int, uintx_t).

Template Parameters
uintAn unsigned integer type.
Returns
The reverse lexicographic number of this permutation.

Definition at line 273 of file Permutation.cpp.

◆ GetSize()

uint8_t CPerm::GetSize ( ) const

Reader function for the size of the permutation, that is, the number of elements being permuted.

Returns
Permutation size.

Definition at line 159 of file Permutation.cpp.

◆ IsIdentity()

bool CPerm::IsIdentity ( ) const

Test whether this is the identity permutation, that is, the permutation that maps everything to itself.

Returns
true If this is the identity permutation.

Definition at line 167 of file Permutation.cpp.

◆ operator *=()

const CPerm & CPerm::operator *= ( const CPerm p)

Permutation composition, that is, post-multiplication by a permutation.

Parameters
pA permutation.
Returns
A reference to this permutation after composition.

Definition at line 255 of file Permutation.cpp.

◆ operator=()

CPerm & CPerm::operator= ( const CPerm p)

Perform a deep copy of a permutation.

Parameters
pA permutation.
Returns
A reference to this permutation after the copy.

Definition at line 214 of file Permutation.cpp.

◆ operator[]()

uint8_t CPerm::operator[] ( uint8_t  n) const

Reader function for the map.

Parameters
nIndex into map.
Returns
nth element of map.

Definition at line 206 of file Permutation.cpp.

◆ printmap()

void CPerm::printmap ( ) const

Print the permutation map on one line as a list of comma-separated numbers.

Definition at line 183 of file Permutation.cpp.

◆ printnum()

void CPerm::printnum ( ) const

Print the reverse lexicographic number as a hexadecimal string.

Definition at line 191 of file Permutation.cpp.

◆ Randomize() [1/2]

void CPerm::Randomize ( uint64_t(*)(void)  rng)

Use the Mersenne Twister to choose a pseudo-random permutation with a uniform distribution, that is, each permutation is equally likely.

Parameters
rngAn external random number generator to use as a seed.

Definition at line 106 of file Permutation.cpp.

◆ Randomize() [2/2]

void CPerm::Randomize ( uint32_t  s[])

Choose a pseudo-random permutation with a uniform distribution, that is, each permutation is equally likely. The parameter consists of an array of numbers that are assumed to be pseudorandom. It is also assumed that the array contains at least m_nSize numbers.

Parameters
sAn array of pseudorandom numbers.

Definition at line 139 of file Permutation.cpp.

◆ RandomizeOdd()

void CPerm::RandomizeOdd ( uint64_t(*)(void)  rng)

Use the Mersenne Twister to choose a pseudo-random odd permutation with a uniform distribution, that is, each odd permutation is equally likely.

Parameters
rngAn external random number generator to use as a seed.

Definition at line 117 of file Permutation.cpp.

Friends And Related Function Documentation

◆ operator==

bool operator== ( const CPerm p0,
const CPerm p1 
)
friend

Test whether a pair of permutations are identical. Permutations are identical iff they are the same size and they have identical maps.

Parameters
p0A permutation.
p1A permutation.
Returns
true if p0 and p1 are identical.

Definition at line 240 of file Permutation.cpp.