Regina Calculation Engine
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
regina::Perm< 3 > Class Reference

Represents a permutation of {0,1,2}. More...

#include <maths/spec/perm3.h>

Public Types

enum  {
  code012 = 0 , code021 = 1 , code120 = 2 , code102 = 3 ,
  code201 = 4 , code210 = 5
}
 
typedef int Index
 Denotes a native signed integer type large enough to count all permutations on three elements. More...
 
typedef uint8_t Code
 Indicates the native unsigned integer type used to store the internal permutation code. More...
 

Public Member Functions

 Perm ()
 Creates the identity permutation. More...
 
 Perm (int a, int b)
 Creates the transposition of a and b. More...
 
 Perm (int a, int b, int c)
 Creates a permutation mapping (0,1,2) to (a,b,c) respectively. More...
 
 Perm (const int *image)
 Creates a permutation mapping i to image[i] for each i = 0,1,2. More...
 
 Perm (const int *a, const int *b)
 Creates a permutation mapping (a[0], ..., a[2]) to (b[0], ..., b[2]) respectively. More...
 
 Perm (const Perm< 3 > &cloneMe)=default
 Creates a permutation that is a clone of the given permutation. More...
 
Code permCode () const
 Returns the internal code representing this permutation. More...
 
void setPermCode (Code code)
 Sets this permutation to that represented by the given internal code. More...
 
Perm< 3 > & operator= (const Perm< 3 > &cloneMe)=default
 Sets this permutation to be equal to the given permutation. More...
 
Perm< 3 > operator* (const Perm< 3 > &q) const
 Returns the composition of this permutation with the given permutation. More...
 
Perm< 3 > inverse () const
 Finds the inverse of this permutation. More...
 
Perm< 3 > reverse () const
 Finds the reverse of this permutation. More...
 
int sign () const
 Determines the sign of this permutation. More...
 
int operator[] (int source) const
 Determines the image of the given integer under this permutation. More...
 
int preImageOf (int image) const
 Determines the preimage of the given integer under this permutation. More...
 
bool operator== (const Perm< 3 > &other) const
 Determines if this is equal to the given permutation. More...
 
bool operator!= (const Perm< 3 > &other) const
 Determines if this differs from the given permutation. More...
 
int compareWith (const Perm< 3 > &other) const
 Lexicographically compares the images of (0,1,2) under this and the given permutation. More...
 
bool isIdentity () const
 Determines if this is the identity permutation. More...
 
Index index () const
 Returns the lexicographical index of this permutation. More...
 
std::string str () const
 Returns a string representation of this permutation. More...
 
std::string trunc (unsigned len) const
 Returns a prefix of the string representation of this permutation, containing only the images of the first len integers. More...
 
std::string trunc2 () const
 Returns a string representation of this permutation with only the images of 0 and 1. More...
 
void clear (unsigned from)
 Resets the images of all integers from from onwards to the identity map. More...
 
int S3Index () const
 Returns the index of this permutation in the Perm<3>::S3 array. More...
 
int SnIndex () const
 Returns the index of this permutation in the Perm<3>::S3 array. More...
 
REGINA_INLINE_REQUIRED int orderedS3Index () const
 Returns the index of this permutation in the Perm<3>::orderedS3 array. More...
 
int orderedSnIndex () const
 Returns the index of this permutation in the Perm<3>::orderedS3 array. More...
 
template<class URBG >
Perm< 3 > rand (URBG &&gen, bool even)
 

Static Public Member Functions

static Perm< 3 > fromPermCode (Code code)
 Creates a permutation from the given internal code. More...
 
static bool isPermCode (Code code)
 Determines whether the given integer is a valid internal permutation code. More...
 
static Perm atIndex (Index i)
 Returns the ith permutation on three elements, where permutations are numbered lexicographically beginning at 0. More...
 
static Perm rand (bool even=false)
 Returns a random permutation on three elements. More...
 
template<class URBG >
static Perm rand (URBG &&gen, bool even=false)
 Returns a random permutation on three elements, using the given uniform random bit generator. More...
 
template<int k>
static Perm< 3 > extend (Perm< k > p)
 Extends a k-element permutation to an 3-element permutation. More...
 
template<int k>
static Perm< 3 > contract (Perm< k > p)
 Restricts a k-element permutation to an 3-element permutation, where k > 3. More...
 

Static Public Attributes

static const Index nPerms = 6
 The total number of permutations on three elements. More...
 
static const Index nPerms_1 = 2
 The total number of permutations on two elements. More...
 
static const Perm< 3 > S3 [6]
 Contains all possible permutations of three elements. More...
 
static const Perm< 3 > * Sn
 A dimension-agnostic alias for Perm<3>::S3. More...
 
static const unsigned invS3 [6]
 Contains the inverses of the permutations in the array S3. More...
 
static const unsigned * invSn
 A dimension-agnostic alias for Perm<3>::invS3. More...
 
static const Perm< 3 > orderedS3 [6]
 Contains all possible permutations of three elements in lexicographical order. More...
 
static const Perm< 3 > * orderedSn
 A dimension-agnostic alias for Perm<3>::orderedS3. More...
 
static const Perm< 3 > S2 [2]
 Contains all possible permutations of two elements. More...
 
static const Perm< 3 > * Sn_1
 A dimension-agnostic alias for Perm<3>::S2. More...
 

Detailed Description

Represents a permutation of {0,1,2}.

This is a specialisation of the generic Perm template: it is highly optimised, and also offers some additional functionality. Amongst other things, this permutation class is used to specify how simplices of a 2-manifold triangulation are glued together.

As with all Perm template classes, these objects are small enough to pass about by value instead of by reference. Moreover, Perm<3> in particular is extremely fast to work with.

Each permutation has an internal code, which is a single native integer that is sufficient to reconstruct the permutation. Thus the internal code may be a useful means for passing permutation objects to and from the engine. For Perm<3>, the internal code is an integer between 0 and 5 inclusive that gives the index of the permutation in the array Perm<3>::S3.

To use this class, simply include the main permutation header maths/perm.h.

Python
Since Python does not support templates, this class is made available under the name Perm3.

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

Copyright © 1999-2021, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@maths.uq.edu.au).