Regina Calculation Engine
|
Represents a permutation of {0,1,2}. More...
#include <maths/nperm3.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 | |
NPerm () | |
Creates the identity permutation. More... | |
NPerm (int a, int b) | |
Creates the transposition of a and b. More... | |
NPerm (int a, int b, int c) | |
Creates a permutation mapping (0,1,2) to (a,b,c) respectively. More... | |
NPerm (const int *image) | |
Creates a permutation mapping i to image[i] for each i = 0,1,2. More... | |
NPerm (const int *a, const int *b) | |
Creates a permutation mapping (a[0], ..., a[2]) to (b[0], ..., b[2]) respectively. More... | |
NPerm (const NPerm< 3 > &cloneMe) | |
Creates a permutation that is a clone of the given permutation. More... | |
Code | permCode () const |
Returns the internal code representing this permutation. More... | |
REGINA_DEPRECATED Code | getPermCode () const |
Deprecated routine that returns the internal code representing this permutation. More... | |
void | setPermCode (Code code) |
Sets this permutation to that represented by the given internal code. More... | |
NPerm< 3 > & | operator= (const NPerm< 3 > &cloneMe) |
Sets this permutation to be equal to the given permutation. More... | |
NPerm< 3 > | operator* (const NPerm< 3 > &q) const |
Returns the composition of this permutation with the given permutation. More... | |
NPerm< 3 > | inverse () const |
Finds the inverse of this permutation. More... | |
NPerm< 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 NPerm< 3 > &other) const |
Determines if this is equal to the given permutation. More... | |
bool | operator!= (const NPerm< 3 > &other) const |
Determines if this differs from the given permutation. More... | |
int | compareWith (const NPerm< 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... | |
int | S3Index () const |
Returns the index of this permutation in the NPerm<3>::S3 array. More... | |
int | SnIndex () const |
Returns the index of this permutation in the NPerm<3>::S3 array. More... | |
REGINA_INLINE_REQUIRED int | orderedS3Index () const |
Returns the index of this permutation in the NPerm<3>::orderedS3 array. More... | |
int | orderedSnIndex () const |
Returns the index of this permutation in the NPerm<3>::orderedS3 array. More... | |
Static Public Member Functions | |
static NPerm< 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 NPerm | atIndex (Index i) |
Returns the ith permutation on three elements, where permutations are numbered lexicographically beginning at 0. More... | |
static NPerm | rand () |
Returns a random permutation on three elements. More... | |
template<int k> | |
static NPerm< 3 > | extend (NPerm< k > p) |
Extends a k-element permutation to an 3-element permutation. More... | |
template<int k> | |
static NPerm< 3 > | contract (NPerm< 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 NPerm< 3 > | S3 [6] |
Contains all possible permutations of three elements. More... | |
static const NPerm< 3 > * | Sn |
A dimension-agnostic alias for NPerm<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 NPerm<3>::invS3. More... | |
static const NPerm< 3 > | orderedS3 [6] |
Contains all possible permutations of three elements in lexicographical order. More... | |
static const NPerm< 3 > * | orderedSn |
A dimension-agnostic alias for NPerm<3>::orderedS3. More... | |
static const NPerm< 3 > | S2 [2] |
Contains all possible permutations of two elements. More... | |
static const NPerm< 3 > * | Sn_1 |
A dimension-agnostic alias for NPerm<3>::S2. More... | |
Represents a permutation of {0,1,2}.
This is a specialisation of the generic NPerm 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 NPerm template classes, these objects are small enough to pass about by value instead of by reference. Moreover, NPerm3 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 NPerm3, the internal code is an integer between 0 and 5 inclusive that gives the index of the permutation in the array NPerm<3>::S3.
typedef uint8_t regina::NPerm< 3 >::Code |
Indicates the native unsigned integer type used to store the internal permutation code.
typedef int regina::NPerm< 3 >::Index |
Denotes a native signed integer type large enough to count all permutations on three elements.
In other words, this is a native signed integer type large enough to store (3!).
anonymous enum |
|
inline |
Creates the identity permutation.
|
inline |
Creates the transposition of a and b.
Note that a and b need not be distinct.
a | the element to switch with b. |
b | the element to switch with a. |
|
inline |
Creates a permutation mapping (0,1,2) to (a,b,c) respectively.
a | the desired image of 0. |
b | the desired image of 1. |
c | the desired image of 2. |
|
inline |
Creates a permutation mapping i to image[i] for each i = 0,1,2.
image | the array of images. |
regina::NPerm< 3 >::NPerm | ( | const int * | a, |
const int * | b | ||
) |
Creates a permutation mapping (a[0], ..., a[2]) to (b[0], ..., b[2]) respectively.
a | the array of preimages; this must have length 3. |
b | the corresponding array of images; this must also have length 3. |
|
inline |
Creates a permutation that is a clone of the given permutation.
cloneMe | the permutation to clone. |
|
inlinestatic |
Returns the ith permutation on three elements, where permutations are numbered lexicographically beginning at 0.
Lexicographical ordering treats each permutation p as the 3-tuple (p[0], p[1], p[2]).
The return value will be identical to orderedS3[i].
i | the lexicographical index of the permutation; this must be between 0 and 5 inclusive. |
|
inline |
Lexicographically compares the images of (0,1,2) under this and the given permutation.
other | the permutation with which to compare this. |
|
static |
Restricts a k-element permutation to an 3-element permutation, where k > 3.
The resulting permutation will map 0,1,2 to their respective images under p, and will ignore the "unused" images p[3],...,p[k-1].
k | the number of elements for the input permutation; this must be strictly greater than 3. |
p | a permutation on k elements. |
|
static |
Extends a k-element permutation to an 3-element permutation.
where 2 ≤ k < 3. The only possible value of k is 2, but this routine is kept as a template function for consistency with the other classes' NPerm<n>::extend() routines.
The resulting permutation will map 0,1 to their respective images under p, and will map the "unused" element 3 to itself.
k | the number of elements for the input permutation; this must be exactly 2. |
p | a permutation on two elements. |
|
inlinestatic |
Creates a permutation from the given internal code.
code | the internal code for the new permutation. |
|
inline |
Deprecated routine that returns the internal code representing this permutation.
|
inline |
Returns the lexicographical index of this permutation.
This indicates where this permutation sits within a full lexicographical ordering of all 3! permutations on three elements.
Lexicographical ordering treats each permutation p as the 3-tuple (p[0], p[1], p[2]). In particular, the identity permutation has index 0, and the "reverse" permutation (which maps each i to 2-i) has index 5 = 3!-1.
This routine is identical to orderedS3Index().
|
inline |
Finds the inverse of this permutation.
|
inline |
Determines if this is the identity permutation.
This is true if and only if each of 0, 1 and 2 is mapped to itself.
true
if and only if this is the identity permutation.
|
inlinestatic |
Determines whether the given integer is a valid internal permutation code.
Valid permutation codes can be passed to setPermCode() or fromPermCode(), and are returned by permCode().
true
if and only if the given code is a valid internal permutation code.
|
inline |
Determines if this differs from the given permutation.
This is true if and only if the two permutations have different images for at least one of 0, 1 or 2.
other | the permutation with which to compare this. |
true
if and only if this and the given permutation differ.
|
inline |
Returns the composition of this permutation with the given permutation.
If this permutation is p, the resulting permutation will be p o q, satisfying (p*q)[x] == p[q[x]]
.
q | the permutation with which to compose this. |
|
inline |
Sets this permutation to be equal to the given permutation.
cloneMe | the permutation whose value will be assigned to this permutation. |
|
inline |
Determines if this is equal to the given permutation.
This is true if and only if both permutations have the same images for 0, 1 and 2.
other | the permutation with which to compare this. |
true
if and only if this and the given permutation are equal.
|
inline |
Determines the image of the given integer under this permutation.
source | the integer whose image we wish to find. This should be between 0 and 2 inclusive. |
|
inline |
Returns the index of this permutation in the NPerm<3>::orderedS3 array.
|
inline |
Returns the index of this permutation in the NPerm<3>::orderedS3 array.
This is a dimension-agnostic alias for orderedS3Index().
|
inline |
Returns the internal code representing this permutation.
Note that the internal code is sufficient to reproduce the entire permutation.
The code returned will be a valid permutation code as determined by isPermCode().
|
inline |
Determines the preimage of the given integer under this permutation.
image | the integer whose preimage we wish to find. This should be between 0 and 2 inclusive. |
|
inlinestatic |
Returns a random permutation on three elements.
All permutations are returned with equal probability.
The implementation uses the C standard ::rand() function for its random number generation.
|
inline |
Finds the reverse of this permutation.
Here reverse means that we reverse the images of 0,1,2. In other words, if permutation q is the reverse of p, then p[i] == q[2 - i]
for all i.
|
inline |
Returns the index of this permutation in the NPerm<3>::S3 array.
|
inline |
Sets this permutation to that represented by the given internal code.
code | the internal code that will determine the new value of this permutation. |
|
inline |
Determines the sign of this permutation.
|
inline |
Returns the index of this permutation in the NPerm<3>::S3 array.
This is a dimension-agnostic alias for S3Index().
std::string regina::NPerm< 3 >::str | ( | ) | const |
Returns a string representation of this permutation.
The representation will consist of three adjacent digits representing the images of 0, 1 and 2 respectively. An example of a string representation is 120
.
std::string regina::NPerm< 3 >::trunc | ( | unsigned | len | ) | const |
Returns a prefix of the string representation of this permutation, containing only the images of the first len integers.
len | the length of the prefix required; this must be between 0 and 3 inclusive. |
std::string regina::NPerm< 3 >::trunc2 | ( | ) | const |
Returns a string representation of this permutation with only the images of 0 and 1.
The resulting string will therefore have length two.
|
static |
Contains the inverses of the permutations in the array S3.
Specifically, the inverse of permutation S3[i]
is the permutation S3[ invS3[i] ]
.
|
static |
A dimension-agnostic alias for NPerm<3>::invS3.
In general, for each K the class NPermK will define an alias invSn that references the list of all permutations NPermK::invSK.
|
static |
The total number of permutations on three elements.
This is the size of the array Sn.
|
static |
The total number of permutations on two elements.
This is the size of the array Sn_1.
|
static |
Contains all possible permutations of three elements in lexicographical order.
|
static |
A dimension-agnostic alias for NPerm<3>::orderedS3.
In general, for each K the class NPermK will define an alias orderedSn that references the list of all permutations NPermK::orderedSK.
|
static |
Contains all possible permutations of two elements.
In each permutation, 2 maps to 2.
The permutations with even indices in the array are the even permutations, and those with odd indices in the array are the odd permutations.
For all permutation classes (NPerm<3>, NPerm4 and so on), the S2 array stores the same permutations in the same order (but of course using different data types).
Note that these permutations are already in lexicographical order.
|
static |
Contains all possible permutations of three elements.
The permutations with even indices in the array are the even permutations, and those with odd indices in the array are the odd permutations.
For all permutation classes (NPerm<3>, NPerm4 and so on), the S3 array stores the same permutations in the same order (but of course using different data types).
Note that these permutations are not necessarily in lexicographical order.
|
static |
A dimension-agnostic alias for NPerm<3>::S3.
In general, for each K the class NPermK will define an alias Sn that references the list of all permutations NPermK::SK.
|
static |
A dimension-agnostic alias for NPerm<3>::S2.
In general, for each K the class NPermK will define an alias Sn_1 that references the list of all permutations NPermK::S(K-1).