Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | Friends

chomp::homology::Simplex Class Reference

This class defines a simplex as a geometric cell that can be used as a member of a geometric complex. More...

#include <simplex.h>

List of all members.

Public Member Functions

 Simplex ()
 The default constructor of the empty simplex.
 Simplex (const int *v, int dim)
 The constructor of a simplex from an array of its vertices.
 Simplex (const Simplex &s, int n)
 The constructor of a boundary simplex.
 ~Simplex ()
 The destructor.
 Simplex (const Simplex &s)
 The copy constructor.
Simplexoperator= (const Simplex &s)
 The assignment operator.
int dim () const
 Returns the dimension of the simplex.
void vertices (int *table) const
 Retrieves the vertices of the simplex to the given array.
int_t hashkey1 () const
 The first hashing key required by the hashing set template.
int_t hashkey2 () const
 The second hashing key required by the hashing set template.

Static Public Member Functions

static const char * name ()
 The singular name of the objects represented by this class.
static const char * pluralname ()
 The plural name of the objects represented by this class.

Static Public Attributes

static const int MaxDim = 2048
 The maximal dimension of a simplex.

Private Attributes

int * tab
 The array that keeps the vertices of the simplex.

Friends

int operator== (const Simplex &s, const Simplex &t)
 The operator == that compares whether the two simplices are the same, that is, have the same vertices in the same order.
std::ostream & operator<< (std::ostream &out, const Simplex &s)
 Writes a simplex to the output stream in the text format.

Detailed Description

This class defines a simplex as a geometric cell that can be used as a member of a geometric complex.

Definition at line 78 of file simplex.h.


Constructor & Destructor Documentation

chomp::homology::Simplex::Simplex (  )  [inline]

The default constructor of the empty simplex.

Definition at line 135 of file simplex.h.

References tab.

{
        tab = NULL;
        return;
} /* Simplex::Simplex */

chomp::homology::Simplex::Simplex ( const int *  v,
int  dim 
) [inline]

The constructor of a simplex from an array of its vertices.

Definition at line 174 of file simplex.h.

References tab.

{
        if (d < 0)
                throw "Negative dimension of a simplex.";
        tab = new int [d + 2];
        if (!tab)
                throw "Not enough memory for a simplex.";
        tab [0] = d;
        for (int i = 0; i <= d; ++ i)
                tab [i + 1] = v [i];
        return;
} /* Simplex::Simplex */

chomp::homology::Simplex::Simplex ( const Simplex s,
int  n 
) [inline]

The constructor of a boundary simplex.

Definition at line 187 of file simplex.h.

References dim(), and tab.

{
        int d = s. dim () - 1;
        if (d < 0)
                throw "Undefined boundary simplex.";
        tab = new int [d + 2];
        if (!tab)
                throw "Not enough memory for a boundary simplex.";
        tab [0] = d;
        int i;
        for (i = 1; i <= n; ++ i)
                tab [i] = s. tab [i];
        for (i = n + 1; i < d + 2; ++ i)
                tab [i] = s. tab [i + 1];
        return;
} /* Simplex::Simplex */

chomp::homology::Simplex::~Simplex (  )  [inline]

The destructor.

Definition at line 141 of file simplex.h.

References tab.

{
        if (tab)
                delete [] tab;
        return;
} /* Simplex::~Simplex */

chomp::homology::Simplex::Simplex ( const Simplex s  )  [inline]

The copy constructor.

Definition at line 204 of file simplex.h.

References dim(), and tab.

{
        int d = s. dim ();
        if (d < 0)
                tab = NULL;
        else
        {
                tab = new int [d + 2];
                if (!tab)
                        throw "Not enough memory to copy a simplex.";
                for (int i = 0; i < d + 2; ++ i)
                        tab [i] = s. tab [i];
        }
        return;
} /* Simplex::Simplex */


Member Function Documentation

int chomp::homology::Simplex::dim (  )  const [inline]

Returns the dimension of the simplex.

The empty simplex has the dimension of -1.

Definition at line 158 of file simplex.h.

References tab.

Referenced by hashkey1(), hashkey2(), operator=(), Simplex(), and vertices().

{
        if (!tab)
                return -1;
        else
                return (*tab);
} /* Simplex::dim */

int_t chomp::homology::Simplex::hashkey1 (  )  const [inline]

The first hashing key required by the hashing set template.

Definition at line 247 of file simplex.h.

References dim(), and tab.

{
        int d = dim ();
        if (d < 0)
                return 0;
        else if (d == 0)
                return static_cast<int_t> (tab [1]) << 2;
        else if (d == 1)
        {
                return ((static_cast<int_t> (tab [1])
                        ^ 0x55555555u) << 16) ^
                        ((static_cast<int_t> (tab [2])
                        ^ 0xAAAA00AAu) << 4);
        }
        else
        {
                return ((static_cast<int_t> (tab [1]) ^
                        0x55555555u) << 16) ^
                        ((static_cast<int_t> (tab [2]) ^
                        0xAA00AAAAu) << 4) ^
                        ((static_cast<int_t> (tab [3]) ^
                        0xAA55AA55u) >> 6);
        }
} /* Simplex::hashkey1 */

int_t chomp::homology::Simplex::hashkey2 (  )  const [inline]

The second hashing key required by the hashing set template.

Definition at line 272 of file simplex.h.

References dim(), and tab.

{
        int d = dim ();
        if (d < 0)
                return 0;
        else if (d == 0)
                return static_cast<int_t> (tab [1]) << 2;
        else if (d == 1)
        {
                return ((static_cast<int_t> (tab [1]) ^
                        0xAAAAAAAAu) >> 1) ^
                        ((static_cast<int_t> (tab [2]) ^
                        0x55555555u) << 13);
        }
        else
        {
                return ((static_cast<int_t> (tab [d + 1]) ^
                        0x55555555u) << 13) ^
                        ((static_cast<int_t> (tab [d]) ^
                        0xAA00AA00u) >> 1) ^
                        ((static_cast<int_t> (tab [d - 1]) ^
                        0xAA0055AAu) << 7);
        }
} /* Simplex::hashkey2 */

const char * chomp::homology::simplex::name (  )  [inline, static]

The singular name of the objects represented by this class.

Definition at line 148 of file simplex.h.

{
        return "simplex";
} /* simplex::name */

Simplex & chomp::homology::Simplex::operator= ( const Simplex s  )  [inline]

The assignment operator.

Definition at line 220 of file simplex.h.

References dim(), and tab.

{
        int d = s. dim ();
        if (d < 0)
        {
                if (tab)
                        delete [] tab;
                tab = NULL;
        }
        else if (d == dim ())
        {
                for (int i = 0; i < d + 2; ++ i)
                        tab [i] = s. tab [i];
        }
        else
        {
                if (tab)
                        delete [] tab;
                tab = new int [d + 2];
                if (!tab)
                        throw "Not enough memory to assign a simplex.";
                for (int i = 0; i < d + 2; ++ i)
                        tab [i] = s. tab [i];
        }
        return *this;
} /* Simplex::operator = */

const char * chomp::homology::simplex::pluralname (  )  [inline, static]

The plural name of the objects represented by this class.

Definition at line 153 of file simplex.h.

{
        return "simplices";
} /* simplex::pluralname */

void chomp::homology::Simplex::vertices ( int *  table  )  const [inline]

Retrieves the vertices of the simplex to the given array.

Definition at line 166 of file simplex.h.

References dim(), and tab.

{
        int d = dim ();
        for (int i = 0; i <= d; ++ i)
                table [i] = tab [i + 1];
        return;
} /* Simplex::dim */


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const Simplex s 
) [friend]

Writes a simplex to the output stream in the text format.

Definition at line 352 of file simplex.h.

{
        out << '(';
        if (s. tab)
        {
                int d = s. dim ();
                out << s. tab [1];
                for (int i = 2; i < d + 2; ++ i)
                        out << ',' << s. tab [i];
        }
        out << ')';
        return out;
} /* operator << */

int operator== ( const Simplex s,
const Simplex t 
) [friend]

The operator == that compares whether the two simplices are the same, that is, have the same vertices in the same order.

Definition at line 301 of file simplex.h.

{
        int sd = s. dim ();
        int td = t. dim ();
        if (sd != td)
                return 0;
        for (int i = 1; i < sd + 2; ++ i)
                if (s. tab [i] != t. tab [i])
                        return 0;
        return 1;
} /* operator == */


Member Data Documentation

const int chomp::homology::Simplex::MaxDim = 2048 [static]

The maximal dimension of a simplex.

Note that practically the maximal dimension in use should not exceed 20 or so.

Definition at line 83 of file simplex.h.

Referenced by chomp::homology::operator>>().

The array that keeps the vertices of the simplex.

The first entry contains the dimension of the simplex.

Definition at line 129 of file simplex.h.

Referenced by dim(), hashkey1(), hashkey2(), operator=(), Simplex(), vertices(), and ~Simplex().


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