regina::NPerm Class Reference
[Triangulations]

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

#include <nperm.h>

List of all members.

Public Member Functions

 NPerm ()
 Creates the identity permutation.
 NPerm (unsigned char newCode)
 Creates a permutation from the given internal code.
 NPerm (int a, int b)
 Creates the transposition of a and b.
 NPerm (int a, int b, int c, int d)
 Creates a permutation mapping (0,1,2,3) to (a,b,c,d) respectively.
 NPerm (int a0, int a1, int b0, int b1, int c0, int c1, int d0, int d1)
 Creates a permutation mapping (a0,b0,c0,d0) to (a1,b1,c1,d1) respectively.
 NPerm (const NPerm &cloneMe)
 Creates a permutation that is a clone of the given permutation.
unsigned char getPermCode () const
 Returns the internal code representing this permutation.
void setPermCode (unsigned char newCode)
 Sets this permutation to that represented by the given internal code.
void setPerm (int a, int b)
 Sets this permutation to the transposition of a and b.
void setPerm (int a, int b, int c, int d)
 Sets this permutation to that mapping (0,1,2,3) to (a,b,c,d) respectively.
NPermoperator= (const NPerm &cloneMe)
 Sets this permutation to be equal to the given permutation.
NPerm operator* (const NPerm &q) const
 Returns the composition of this permutation with the given permutation.
NPerm inverse () const
 Finds the inverse of this permutation.
int sign () const
 Determines the sign of this permutation.
int operator[] (int source) const
 Determines the image of the given integer under this permutation.
int preImageOf (int image) const
 Determines the preimage of the given integer under this permutation.
bool operator== (const NPerm &other) const
 Determines if this is equal to the given permutation.
bool operator!= (const NPerm &other) const
 Determines if this differs from the given permutation.
int compareWith (const NPerm &other) const
 Lexicographically compares the images of (0,1,2,3) under this and the given permutation.
bool isIdentity () const
 Determines if this is the identity permutation.
std::string toString () const
 Returns a string representation of this permutation.

Static Public Member Functions

static bool isPermCode (unsigned char newCode)
 Determines whether the given character is a valid internal permutation code.

Friends

std::ostream & operator<< (std::ostream &out, const NPerm &p)
 Writes a string representation of the given permutation to the given output stream.


Detailed Description

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

Such permutations are used in specifying how simplices are glued together. NPerm objects are small enough to pass about by value instead of by reference.

Each permutation has an internal code, and this code is sufficient to reconstruct the permutation. Thus the internal code may be a useful means for passing permutation objects to and from the engine.

The internal code is a character. The lowest two bits represent the image of 0, the next lowest two bits represent the image of 1 and so on.

Test:
Tested in the test suite, though not exhaustively.

Constructor & Destructor Documentation

regina::NPerm::NPerm (  )  [inline]

Creates the identity permutation.

regina::NPerm::NPerm ( unsigned char  newCode  )  [inline]

Creates a permutation from the given internal code.

Precondition:
the given code is a valid permutation code; see isPermCode() for details.
Parameters:
newCode the internal code from which the new permutation will be created.

regina::NPerm::NPerm ( int  a,
int  b 
) [inline]

Creates the transposition of a and b.

Note that a and b need not be distinct.

Precondition:
a and b are in {0,1,2,3}.
Parameters:
a the element to switch with b.
b the element to switch with a.

regina::NPerm::NPerm ( int  a,
int  b,
int  c,
int  d 
) [inline]

Creates a permutation mapping (0,1,2,3) to (a,b,c,d) respectively.

Precondition:
{a,b,c,d} = {0,1,2,3}.
Parameters:
a the desired image of 0.
b the desired image of 1.
c the desired image of 2.
d the desired image of 3.

regina::NPerm::NPerm ( int  a0,
int  a1,
int  b0,
int  b1,
int  c0,
int  c1,
int  d0,
int  d1 
) [inline]

Creates a permutation mapping (a0,b0,c0,d0) to (a1,b1,c1,d1) respectively.

Precondition:
{a0,b0,c0,d0} = {a1,b1,c1,d1} = {0,1,2,3}.
Parameters:
a0 the desired preimage of a1.
b0 the desired preimage of b1.
c0 the desired preimage of c1.
d0 the desired preimage of d1.
a1 the desired image of a0.
b1 the desired image of b0.
c1 the desired image of c0.
d1 the desired image of d0.

regina::NPerm::NPerm ( const NPerm cloneMe  )  [inline]

Creates a permutation that is a clone of the given permutation.

Parameters:
cloneMe the permutation to clone.


Member Function Documentation

int regina::NPerm::compareWith ( const NPerm other  )  const

Lexicographically compares the images of (0,1,2,3) under this and the given permutation.

Parameters:
other the permutation with which to compare this.
Returns:
-1 if this permutation produces a smaller image, 0 if the permutations are equal and 1 if this permutation produces a greater image.

unsigned char regina::NPerm::getPermCode (  )  const [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().

Returns:
the internal code.

NPerm regina::NPerm::inverse (  )  const [inline]

Finds the inverse of this permutation.

Returns:
the inverse of this permutation.

bool regina::NPerm::isIdentity (  )  const [inline]

Determines if this is the identity permutation.

This is true if and only if each of 0, 1, 2 and 3 is mapped to itself.

Returns:
true if and only if this is the identity permutation.

static bool regina::NPerm::isPermCode ( unsigned char  newCode  )  [static]

Determines whether the given character is a valid internal permutation code.

Valid permutation codes can be passed to setPermCode() or NPerm(char) and are returned by getPermCode().

Returns:
true if and only if the given code is a valid internal permutation code.

bool regina::NPerm::operator!= ( const NPerm other  )  const [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, 2 or 3.

Parameters:
other the permutation with which to compare this.
Returns:
true if and only if this and the given permutation differ.

NPerm regina::NPerm::operator* ( const NPerm q  )  const [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]].

Parameters:
q the permutation with which to compose this.
Returns:
the composition of both permutations.

NPerm & regina::NPerm::operator= ( const NPerm cloneMe  )  [inline]

Sets this permutation to be equal to the given permutation.

Parameters:
cloneMe the permutation whose value will be assigned to this permutation.
Returns:
a reference to this permutation.

bool regina::NPerm::operator== ( const NPerm other  )  const [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, 2 and 3.

Parameters:
other the permutation with which to compare this.
Returns:
true if and only if this and the given permutation are equal.

int regina::NPerm::operator[] ( int  source  )  const [inline]

Determines the image of the given integer under this permutation.

Parameters:
source the integer whose image we wish to find. This should be between 0 and 3 inclusive.
Returns:
the image of source.

int regina::NPerm::preImageOf ( int  image  )  const [inline]

Determines the preimage of the given integer under this permutation.

Parameters:
image the integer whose preimage we wish to find. This should be between 0 and 3 inclusive.
Returns:
the preimage of image.

void regina::NPerm::setPerm ( int  a,
int  b,
int  c,
int  d 
) [inline]

Sets this permutation to that mapping (0,1,2,3) to (a,b,c,d) respectively.

Precondition:
{a,b,c,d} = {0,1,2,3}.
Parameters:
a the desired image of 0.
b the desired image of 1.
c the desired image of 2.
d the desired image of 3.

void regina::NPerm::setPerm ( int  a,
int  b 
) [inline]

Sets this permutation to the transposition of a and b.

Note that a and b need not be distinct.

Precondition:
a and b are in {0,1,2,3}.
Parameters:
a the element to switch with b.
b the element to switch with a.

void regina::NPerm::setPermCode ( unsigned char  newCode  )  [inline]

Sets this permutation to that represented by the given internal code.

Precondition:
the given code is a valid permutation code; see isPermCode() for details.
Parameters:
newCode the internal code that will determine the new value of this permutation.

int regina::NPerm::sign (  )  const

Determines the sign of this permutation.

Returns:
1 if this permutation is even, or -1 if this permutation is odd.

std::string regina::NPerm::toString (  )  const

Returns a string representation of this permutation.

The representation will consist of four adjacent digits representing the images of 0, 1, 2 and 3 respectively. An example of a string representation is 1302.

Returns:
a string representation of this permutation.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const NPerm p 
) [friend]

Writes a string representation of the given permutation to the given output stream.

The format will be the same as is used by NPerm::toString().

Parameters:
out the output stream to which to write.
p the permutation to write.
Returns:
a reference to out.


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

Copyright © 1999-2008, Ben Burton
This software is released under the GNU General Public License.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).