23 #ifndef SHEAF_DLL_SPEC_H 24 #include "SheafSystem/sheaf_dll_spec.h" 28 #include "SheafSystem/pool.h" 31 #ifndef ASSERT_CONTRACT_H 32 #include "SheafSystem/assert_contract.h" 36 #include "SheafSystem/std_iomanip.h" 40 #include "SheafSystem/zn_to_bool.h" 46 template <
typename T,
int EXTENSION_FACTOR>
55 invariance(_pool.ub() == _is_allocated->ub());
62 template <
typename T,
int EXTENSION_FACTOR>
82 template <
typename T,
int EXTENSION_FACTOR>
87 return (0 <= xitem) && (xitem < _pool.ub());
90 template <
typename T,
int EXTENSION_FACTOR>
98 template <
typename T,
int EXTENSION_FACTOR>
106 template <
typename T,
int EXTENSION_FACTOR>
111 return _allocated_ct;
114 template <
typename T,
int EXTENSION_FACTOR>
123 require(index_in_bounds(xindex));
127 result = (*_is_allocated)[xindex];
136 template <
typename T,
int EXTENSION_FACTOR>
156 template <
typename T,
int EXTENSION_FACTOR>
167 extend_to(new_index_ub);
176 _free_list = _pool[result]->next();
179 _is_allocated->put(result,
true);
190 ensure(is_allocated(result));
191 ensure(unexecutable(free_ct() == old free_ct() - 1));
192 ensure(unexecutable(allocated_ct() == old allocated_ct() + 1));
197 template <
typename T,
int EXTENSION_FACTOR>
204 require(is_allocated(xindex));
208 T* item = _pool.item(xindex);
210 item->put_next(_free_list);
213 _is_allocated->put(xindex,
false);
218 ensure(!is_allocated(xindex));
219 ensure(unexecutable(free_ct() == old free_ct() + 1));
220 ensure(unexecutable(allocated_ct() == old allocated_ct() - 1));
227 template <
typename T,
int EXTENSION_FACTOR>
246 ensure(index_ub() == xub);
247 ensure(free_ct() == xub);
248 ensure(free_list() == 0);
249 ensure(allocated_ct() == 0);
256 template <
typename T,
int EXTENSION_FACTOR>
262 while(!_chunk_list.empty())
264 T* lchunk = _chunk_list.front();
266 _chunk_list.pop_front();
271 delete _is_allocated;
275 template <
typename T,
int EXTENSION_FACTOR>
283 require(index_in_bounds(xindex));
287 T& result = *(_pool.item(xindex));
294 template <
typename T,
int EXTENSION_FACTOR>
302 require(index_in_bounds(xindex));
306 T& result = *(_pool[xindex]);
313 template <
typename T,
int EXTENSION_FACTOR>
321 require(xub > index_ub());
332 size_type lchunk_size = new_pool_ub - old_pool_ub;
333 T* lchunk =
new T[lchunk_size];
334 _chunk_list.push_front(lchunk);
338 _pool.reserve(new_pool_ub);
343 T* lmbr_ptr = lchunk;
344 for(
int i=0; i<lchunk_size; i++)
346 _pool.push_back(lmbr_ptr++);
351 _is_allocated->extend_to(new_pool_ub);
360 assertion(last_new_mbr_id >= old_index_ub);
365 _pool.item(old_i)->put_next(++i);
376 _free_list = old_index_ub;
384 while(
is_valid(_pool.item(last_free_mbr)->next()))
386 last_free_mbr = _pool.item(last_free_mbr)->next();
391 _pool.item(last_free_mbr)->put_next(old_index_ub);
396 _free_ct += (new_pool_ub - old_pool_ub);
406 template <
typename T,
int EXTENSION_FACTOR>
414 template <
typename T,
int EXTENSION_FACTOR>
428 <<
" allocated_ct = " 437 os <<
"member: " << std::setw(5) << i <<
" ";
451 template <
typename T,
int EXTENSION_FACTOR>
463 result = xinclude_shallow ?
sizeof(xpool) : 0;
472 result += lindex_ub*
sizeof(T);
478 if(lpool.is_allocated(i))
480 result +=
deep_size(lpool.item(i),
false);
492 result += lpool._chunk_list.size()*(
sizeof(T*) +
sizeof(
void*));
497 if(lpool._is_allocated != 0)
499 result +=
deep_size(*(lpool._is_allocated),
true);
513 #endif // ifndef POOL_IMPL_H int free_ct() const
The size of free list.
index_iterator allocated_iterator() const
An iterator over allocated items in the pool.
bool is_allocated(pod_index_type xindex) const
True if xindex is allocated.
bool invariant() const
Class invariant.
unsigned long int size_type
An unsigned integral type used to represent sizes and capacities.
A map from Zn (the integers mod n) to bools. A characteristic function used to represent subsets of Z...
void deallocate(pod_index_type xindex)
Deallocate item at xindex.
int allocated_ct() const
The size of allocated list.
pod_index_type index_ub() const
The upper bound on the index for members of the pool.
A reallocatable pool of objects of type T. Objects in the pool are either "allocated" or linked toget...
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
Iterates over the subset of Zn defined by the characteristic function host().
int_type pod_index_type
The plain old data index type.
pod_index_type index_type
The containers index type.
void print() const
Prints the data members of this on cout. Intended for use debugging.
T & item(pod_index_type xindex)
A pointer to the pool item at xindex.
Namespace for the sheaves component of the sheaf system.
bool index_in_bounds(pod_index_type xindex) const
True if xindex is in bounds.
pool(pod_index_type xub)
Creates an instance with xub upper bound.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
pod_index_type free_list() const
The head of the free list.
T & operator[](pod_index_type xindex)
A reference to the pool item at xindex.
pod_index_type allocate()
Allocate next available index from free list.