The Original CHomP Software
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | Friends | List of all members
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>

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

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

Private Attributes

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

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. More...
 
std::ostream & operator<< (std::ostream &out, const Simplex &s)
 Writes a simplex to the output stream in the text format. More...
 

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 77 of file simplex.h.

Constructor & Destructor Documentation

◆ Simplex() [1/4]

chomp::homology::Simplex::Simplex ( )
inline

The default constructor of the empty simplex.

Definition at line 134 of file simplex.h.

135{
136 tab = NULL;
137 return;
138} /* Simplex::Simplex */
int * tab
The array that keeps the vertices of the simplex.
Definition: simplex.h:128

References tab.

◆ Simplex() [2/4]

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

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

Definition at line 173 of file simplex.h.

174{
175 if (d < 0)
176 throw "Negative dimension of a simplex.";
177 tab = new int [d + 2];
178 if (!tab)
179 throw "Not enough memory for a simplex.";
180 tab [0] = d;
181 for (int i = 0; i <= d; ++ i)
182 tab [i + 1] = v [i];
183 return;
184} /* Simplex::Simplex */

References tab.

◆ Simplex() [3/4]

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

The constructor of a boundary simplex.

Definition at line 186 of file simplex.h.

187{
188 int d = s. dim () - 1;
189 if (d < 0)
190 throw "Undefined boundary simplex.";
191 tab = new int [d + 2];
192 if (!tab)
193 throw "Not enough memory for a boundary simplex.";
194 tab [0] = d;
195 int i;
196 for (i = 1; i <= n; ++ i)
197 tab [i] = s. tab [i];
198 for (i = n + 1; i < d + 2; ++ i)
199 tab [i] = s. tab [i + 1];
200 return;
201} /* Simplex::Simplex */
int dim() const
Returns the dimension of the simplex.
Definition: simplex.h:157

References dim(), and tab.

◆ ~Simplex()

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

The destructor.

Definition at line 140 of file simplex.h.

141{
142 if (tab)
143 delete [] tab;
144 return;
145} /* Simplex::~Simplex */

References tab.

◆ Simplex() [4/4]

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

The copy constructor.

Definition at line 203 of file simplex.h.

204{
205 int d = s. dim ();
206 if (d < 0)
207 tab = NULL;
208 else
209 {
210 tab = new int [d + 2];
211 if (!tab)
212 throw "Not enough memory to copy a simplex.";
213 for (int i = 0; i < d + 2; ++ i)
214 tab [i] = s. tab [i];
215 }
216 return;
217} /* Simplex::Simplex */

References dim(), and tab.

Member Function Documentation

◆ dim()

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

Returns the dimension of the simplex.

The empty simplex has the dimension of -1.

Definition at line 157 of file simplex.h.

158{
159 if (!tab)
160 return -1;
161 else
162 return (*tab);
163} /* Simplex::dim */

References tab.

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

◆ hashkey1()

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

The first hashing key required by the hashing set template.

Definition at line 246 of file simplex.h.

247{
248 int d = dim ();
249 if (d < 0)
250 return 0;
251 else if (d == 0)
252 return static_cast<int_t> (tab [1]) << 2;
253 else if (d == 1)
254 {
255 return ((static_cast<int_t> (tab [1])
256 ^ 0x55555555u) << 16) ^
257 ((static_cast<int_t> (tab [2])
258 ^ 0xAAAA00AAu) << 4);
259 }
260 else
261 {
262 return ((static_cast<int_t> (tab [1]) ^
263 0x55555555u) << 16) ^
264 ((static_cast<int_t> (tab [2]) ^
265 0xAA00AAAAu) << 4) ^
266 ((static_cast<int_t> (tab [3]) ^
267 0xAA55AA55u) >> 6);
268 }
269} /* Simplex::hashkey1 */
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115

References dim(), and tab.

◆ hashkey2()

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

The second hashing key required by the hashing set template.

Definition at line 276 of file simplex.h.

277{
278 int d = dim ();
279 if (d < 0)
280 return 0;
281 else if (d == 0)
282 return static_cast<int_t> (tab [1]) << 2;
283 else if (d == 1)
284 {
285 return ((static_cast<int_t> (tab [1]) ^
286 0xAAAAAAAAu) >> 1) ^
287 ((static_cast<int_t> (tab [2]) ^
288 0x55555555u) << 13);
289 }
290 else
291 {
292 return ((static_cast<int_t> (tab [d + 1]) ^
293 0x55555555u) << 13) ^
294 ((static_cast<int_t> (tab [d]) ^
295 0xAA00AA00u) >> 1) ^
296 ((static_cast<int_t> (tab [d - 1]) ^
297 0xAA0055AAu) << 7);
298 }
299} /* Simplex::hashkey2 */

References dim(), and tab.

◆ name()

const char * chomp::homology::simplex::name ( )
inlinestatic

The singular name of the objects represented by this class.

Definition at line 147 of file simplex.h.

148{
149 return "simplex";
150} /* simplex::name */

◆ operator=()

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

The assignment operator.

Definition at line 219 of file simplex.h.

220{
221 int d = s. dim ();
222 if (d < 0)
223 {
224 if (tab)
225 delete [] tab;
226 tab = NULL;
227 }
228 else if (d == dim ())
229 {
230 for (int i = 0; i < d + 2; ++ i)
231 tab [i] = s. tab [i];
232 }
233 else
234 {
235 if (tab)
236 delete [] tab;
237 tab = new int [d + 2];
238 if (!tab)
239 throw "Not enough memory to assign a simplex.";
240 for (int i = 0; i < d + 2; ++ i)
241 tab [i] = s. tab [i];
242 }
243 return *this;
244} /* Simplex::operator = */

References dim(), and tab.

◆ pluralname()

const char * chomp::homology::simplex::pluralname ( )
inlinestatic

The plural name of the objects represented by this class.

Definition at line 152 of file simplex.h.

153{
154 return "simplices";
155} /* simplex::pluralname */

◆ vertices()

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

Retrieves the vertices of the simplex to the given array.

Definition at line 165 of file simplex.h.

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

References dim(), and tab.

Friends And Related Function Documentation

◆ operator<<

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

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

Definition at line 361 of file simplex.h.

362{
363 out << '(';
364 if (s. tab)
365 {
366 int d = s. dim ();
367 out << s. tab [1];
368 for (int i = 2; i < d + 2; ++ i)
369 out << ',' << s. tab [i];
370 }
371 out << ')';
372 return out;
373} /* operator << */

◆ 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 310 of file simplex.h.

311{
312 int sd = s. dim ();
313 int td = t. dim ();
314 if (sd != td)
315 return 0;
316 for (int i = 1; i < sd + 2; ++ i)
317 if (s. tab [i] != t. tab [i])
318 return 0;
319 return 1;
320} /* operator == */

Member Data Documentation

◆ MaxDim

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 82 of file simplex.h.

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

◆ tab

int* chomp::homology::Simplex::tab
private

The array that keeps the vertices of the simplex.

The first entry contains the dimension of the simplex.

Definition at line 128 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: