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

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

#include <maths/spec/perm2.h>

Public Types

typedef int Index
 Denotes a native signed integer type large enough to count all permutations on two 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 (const int *image)
 Creates a permutation mapping i to image[i] for each i = 0,1. More...
 
 Perm (const int *a, const int *b)
 Creates a permutation mapping (a[0], a[1]) to (b[0], b[1]) respectively. More...
 
 Perm (const Perm< 2 > &cloneMe)
 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< 2 > & operator= (const Perm< 2 > &cloneMe)
 Sets this permutation to be equal to the given permutation. More...
 
Perm< 2 > operator* (const Perm< 2 > &q) const
 Returns the composition of this permutation with the given permutation. More...
 
Perm< 2 > inverse () const
 Finds the inverse of this permutation. More...
 
Perm< 2 > 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< 2 > &other) const
 Determines if this is equal to the given permutation. More...
 
bool operator!= (const Perm< 2 > &other) const
 Determines if this differs from the given permutation. More...
 
int compareWith (const Perm< 2 > &other) const
 Lexicographically compares the images of (0,1) 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...
 
void clear (unsigned from)
 Resets the images of all integers from from onwards to the identity map. More...
 
int S2Index () const
 Returns the index of this permutation in the Perm<2>::S2 array. More...
 
int SnIndex () const
 Returns the index of this permutation in the Perm<2>::S2 array. More...
 
int orderedS2Index () const
 Returns the index of this permutation in the Perm<2>::orderedS2 array. More...
 
int orderedSnIndex () const
 Returns the index of this permutation in the Perm<2>::orderedS2 array. More...
 

Static Public Member Functions

static Perm< 2 > 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 two elements, where permutations are numbered lexicographically beginning at 0. More...
 
static Perm rand ()
 Returns a random permutation on two elements. More...
 
template<int k>
static Perm< 2 > contract (Perm< k > p)
 Restricts a k-element permutation to an 2-element permutation, where k > 2. More...
 

Static Public Attributes

static const Index nPerms = 2
 The total number of permutations on two elements. More...
 
static const Index nPerms_1 = 1
 The total number of permutations on one element. More...
 
static const Perm< 2 > S2 [2]
 Contains all possible permutations of two elements. More...
 
static const Perm< 2 > * Sn
 A dimension-agnostic alias for Perm<2>::S2. More...
 
static const unsigned invS2 [2]
 Contains the inverses of the permutations in the array S2. More...
 
static const unsigned * invSn
 A dimension-agnostic alias for Perm<2>::invS2. More...
 
static const Perm< 2 > * orderedS2
 Contains all possible permutations of two elements in lexicographical order. More...
 
static const Perm< 2 > * orderedSn
 A dimension-agnostic alias for Perm<2>::orderedS2. More...
 
static const Perm< 2 > * S1
 Contains all possible permutations of one element. More...
 
static const Perm< 2 > * Sn_1
 A dimension-agnostic alias for Perm<2>::S1. More...
 

Detailed Description

template<>
class regina::Perm< 2 >

Represents a permutation of {0,1}.

This is a specialisation of the generic Perm template: it is highly optimised, but also somewhat trivial (since there are only two possible permutations). It is provided simply to optimise the general Perm<n> template for this trivial case.

As with all Perm template classes, these objects are small enough to pass about by value instead of by reference. Moreover, Perm<2> 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<2>, the internal code is 0 for the identity permutation, or 1 for the (unique) non-identity permutation.

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

Warning
Every permutation class Perm<n> provides a transposition (i.e., pair swap) constructor Perm<n>(a,b). In addition, the specialised classes Perm<3>, Perm<4> and Perm<5> provide "list of images" constructors Perm<3>(a,b,c), Perm<4>(a,b,c,d) and Perm<5>(a,b,c,d,e). For Perm<2>, these two constructors would be indistinguishable (since both would take two integer arguments). Here Perm<2> takes an approach that is consistent with the generic Perm<n> class: Perm<2>(a,b) is interpreted as the transposition of a and b. In particular, Perm(0,1) is not the identity permutation.
Python:\n Since Python does not support templates, this class is
made available under the name Perm2.

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

Copyright © 1999-2016, 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).