This template contains the definition of a pool of elements that are stored in an extensible table. More...
#include <pool.h>
Public Member Functions | |
pool () | |
The constructor of a pool. | |
~pool () | |
The destructor of a pool. | |
int | get () |
Allocates a new element in the pool or finds a used one. | |
element & | operator[] (int number) |
Retrieves the element in the pool with the given number. | |
void | release (int number) |
Marks the given element as unused and available for retrieval the next time the pool is asked for an element. | |
Private Member Functions | |
pool (const pool< element > &) | |
The copy constructor is not allowed. | |
pool< element > & | operator= (const pool< element > &) |
The assignment operator is not allowed. | |
Private Attributes | |
multitable< element > | elem |
The multitable of elements. | |
int | elemCount |
The number of elements in the multitable. | |
multitable< int > | unused |
The multitable with indices of unused elements. | |
int | unusedCount |
The number of unused elements in the multitable. |
This template contains the definition of a pool of elements that are stored in an extensible table.
Elements that are returned to the pool can be reused. Indexing of the elements is done by integer numbers.
Definition at line 55 of file pool.h.
chomp::homology::pool< element >::pool | ( | ) | [inline] |
The constructor of a pool.
Definition at line 99 of file pool.h.
: elemCount (0), unusedCount (0) { return; } /* pool::pool */
chomp::homology::pool< element >::~pool | ( | ) | [inline] |
chomp::homology::pool< element >::pool | ( | const pool< element > & | ) | [inline, private] |
int chomp::homology::pool< element >::get | ( | ) | [inline] |
Allocates a new element in the pool or finds a used one.
Returns its number.
Definition at line 125 of file pool.h.
References chomp::homology::pool< element >::elemCount, chomp::homology::pool< element >::unused, and chomp::homology::pool< element >::unusedCount.
{ if (unusedCount) return unused [-- unusedCount]; else return elemCount ++; } /* pool::get */
pool< element > & chomp::homology::pool< element >::operator= | ( | const pool< element > & | ) | [inline, private] |
element & chomp::homology::pool< element >::operator[] | ( | int | number | ) | [inline] |
Retrieves the element in the pool with the given number.
Definition at line 134 of file pool.h.
References chomp::homology::pool< element >::elem.
{ return elem [n]; } /* pool::operator [] */
void chomp::homology::pool< element >::release | ( | int | number | ) | [inline] |
Marks the given element as unused and available for retrieval the next time the pool is asked for an element.
Definition at line 140 of file pool.h.
References chomp::homology::pool< element >::elemCount, chomp::homology::pool< element >::unused, and chomp::homology::pool< element >::unusedCount.
{ if (n == elemCount - 1) -- elemCount; else unused [unusedCount ++] = n; return; } /* pool::release */
multitable<element> chomp::homology::pool< element >::elem [private] |
The multitable of elements.
Definition at line 83 of file pool.h.
Referenced by chomp::homology::pool< element >::operator[]().
int chomp::homology::pool< element >::elemCount [private] |
The number of elements in the multitable.
Definition at line 86 of file pool.h.
Referenced by chomp::homology::pool< element >::get(), and chomp::homology::pool< element >::release().
multitable<int> chomp::homology::pool< element >::unused [private] |
The multitable with indices of unused elements.
Definition at line 89 of file pool.h.
Referenced by chomp::homology::pool< element >::get(), and chomp::homology::pool< element >::release().
int chomp::homology::pool< element >::unusedCount [private] |
The number of unused elements in the multitable.
Definition at line 92 of file pool.h.
Referenced by chomp::homology::pool< element >::get(), and chomp::homology::pool< element >::release().