The Original CHomP Software
pool.h
Go to the documentation of this file.
1
3
14
15// Copyright (C) 1997-2020 by Pawel Pilarczyk.
16//
17// This file is part of my research software package. This is free software:
18// you can redistribute it and/or modify it under the terms of the GNU
19// General Public License as published by the Free Software Foundation,
20// either version 3 of the License, or (at your option) any later version.
21//
22// This software is distributed in the hope that it will be useful,
23// but WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25// GNU General Public License for more details.
26//
27// You should have received a copy of the GNU General Public License
28// along with this software; see the file "license.txt". If not,
29// please, see <https://www.gnu.org/licenses/>.
30
31// Started on August 13, 2007. Last revision: August 13, 2007.
32
33
34#ifndef _CHOMP_STRUCT_POOL_H_
35#define _CHOMP_STRUCT_POOL_H_
36
37
39
40
41namespace chomp {
42namespace homology {
43
44
45// --------------------------------------------------
46// ---------------------- POOL ----------------------
47// --------------------------------------------------
48
53template <class element>
54class pool
55{
56public:
58 pool ();
59
61 ~pool ();
62
65 int get ();
66
68 element &operator [] (int number);
69
72 void release (int number);
73
74private:
76 pool (const pool<element> &);
77
80
83
86
89
92
93}; /* class pool */
94
95// --------------------------------------------------
96
97template <class element>
98inline pool<element>::pool (): elemCount (0), unusedCount (0)
99{
100 return;
101} /* pool::pool */
102
103template <class element>
105{
106 return;
107} /* pool::~pool */
108
109template <class element>
111{
112 throw "Copy constructor for a pool not implemented.";
113 return;
114} /* pool::pool */
115
116template <class element>
118{
119 throw "Assignment operator for a pool not implemented.";
120 return *this;
121} /* pool::operator = */
122
123template <class element>
125{
126 if (unusedCount)
127 return unused [-- unusedCount];
128 else
129 return elemCount ++;
130} /* pool::get */
131
132template <class element>
133inline element &pool<element>::operator [] (int n)
134{
135 return elem [n];
136} /* pool::operator [] */
137
138template <class element>
139inline void pool<element>::release (int n)
140{
141 if (n == elemCount - 1)
142 -- elemCount;
143 else
144 unused [unusedCount ++] = n;
145 return;
146} /* pool::release */
147
148
149} // namespace homology
150} // namespace chomp
151
152#endif // _CHOMP_STRUCT_POOL_H_
153
155
A container for elements placed in a table (like a vector) that is actually built of many smaller tab...
Definition: multitab.h:65
This template contains the definition of a pool of elements that are stored in an extensible table.
Definition: pool.h:55
multitable< int > unused
The multitable with indices of unused elements.
Definition: pool.h:88
~pool()
The destructor of a pool.
Definition: pool.h:104
void release(int number)
Marks the given element as unused and available for retrieval the next time the pool is asked for an ...
Definition: pool.h:139
pool()
The constructor of a pool.
Definition: pool.h:98
int elemCount
The number of elements in the multitable.
Definition: pool.h:85
int unusedCount
The number of unused elements in the multitable.
Definition: pool.h:91
int get()
Allocates a new element in the pool or finds a used one.
Definition: pool.h:124
pool< element > & operator=(const pool< element > &)
The assignment operator is not allowed.
Definition: pool.h:117
element & operator[](int number)
Retrieves the element in the pool with the given number.
Definition: pool.h:133
multitable< element > elem
The multitable of elements.
Definition: pool.h:82
This file contains the definition of the container "multitable" which is essentially an automatically...
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51