SheafSystem  0.0.0.0
sheaf::pool< T, EXTENSION_FACTOR > Class Template Reference

A reallocatable pool of objects of type T. Objects in the pool are either "allocated" or linked together into a "free" list. Intended to support efficient allocation and deallocation of nodes in a graph or other dynamic data structure. There is an implicit constraint on T: it must have a next() feature. More...

#include <pool.h>

Public Types

typedef T value_type
 The container's value type. More...
 
typedef T & reference_type
 A type that behaves as a reference to the container's value type. More...
 
typedef const T & const_reference_type
 A type that behaves as a const reference to the container's value type. More...
 
typedef T * pointer_type
 A type that behaves as a pointer to the container's value type. More...
 
typedef const T * const_pointer_type
 A type that behaves as a const pointer to the container's value type. More...
 
typedef pod_index_type index_type
 The containers index type. More...
 
typedef pod_index_type difference_type
 A signed integral type used to represent the difference of two indices or iterators. More...
 
typedef unsigned long int size_type
 An unsigned integral type used to represent sizes and capacities. More...
 

Public Member Functions

bool invariant () const
 Class invariant. More...
 
pod_index_type index_ub () const
 The upper bound on the index for members of the pool. More...
 
bool index_in_bounds (pod_index_type xindex) const
 True if xindex is in bounds. More...
 
int free_ct () const
 The size of free list. More...
 
pod_index_type free_list () const
 The head of the free list. More...
 
int allocated_ct () const
 The size of allocated list. More...
 
bool is_allocated (pod_index_type xindex) const
 True if xindex is allocated. More...
 
T & item (pod_index_type xindex)
 A pointer to the pool item at xindex. More...
 
T & operator[] (pod_index_type xindex)
 A reference to the pool item at xindex. More...
 
index_iterator allocated_iterator () const
 An iterator over allocated items in the pool. More...
 
pod_index_type allocate ()
 Allocate next available index from free list. More...
 
void deallocate (pod_index_type xindex)
 Deallocate item at xindex. More...
 
void print () const
 Prints the data members of this on cout. Intended for use debugging. More...
 
void print (std::ostream &out) const
 Prints the data members of this on cout. Intended for use debugging. More...
 
 pool (pod_index_type xub)
 Creates an instance with xub upper bound. More...
 
 ~pool ()
 Destructor. More...
 

Friends

size_t deep_size (const pool< T, EXTENSION_FACTOR > &xpool, bool xinclude_shallow)
 The deep size of the referenced object of type pool<T, int>. More...
 

Detailed Description

template<typename T, int EXTENSION_FACTOR = 2>
class sheaf::pool< T, EXTENSION_FACTOR >

A reallocatable pool of objects of type T. Objects in the pool are either "allocated" or linked together into a "free" list. Intended to support efficient allocation and deallocation of nodes in a graph or other dynamic data structure. There is an implicit constraint on T: it must have a next() feature.

Definition at line 55 of file pool.h.

Member Typedef Documentation

◆ const_pointer_type

template<typename T, int EXTENSION_FACTOR = 2>
typedef const T* sheaf::pool< T, EXTENSION_FACTOR >::const_pointer_type

A type that behaves as a const pointer to the container's value type.

Definition at line 99 of file pool.h.

◆ const_reference_type

template<typename T, int EXTENSION_FACTOR = 2>
typedef const T& sheaf::pool< T, EXTENSION_FACTOR >::const_reference_type

A type that behaves as a const reference to the container's value type.

Definition at line 89 of file pool.h.

◆ difference_type

template<typename T, int EXTENSION_FACTOR = 2>
typedef pod_index_type sheaf::pool< T, EXTENSION_FACTOR >::difference_type

A signed integral type used to represent the difference of two indices or iterators.

Definition at line 110 of file pool.h.

◆ index_type

template<typename T, int EXTENSION_FACTOR = 2>
typedef pod_index_type sheaf::pool< T, EXTENSION_FACTOR >::index_type

The containers index type.

Definition at line 104 of file pool.h.

◆ pointer_type

template<typename T, int EXTENSION_FACTOR = 2>
typedef T* sheaf::pool< T, EXTENSION_FACTOR >::pointer_type

A type that behaves as a pointer to the container's value type.

Definition at line 94 of file pool.h.

◆ reference_type

template<typename T, int EXTENSION_FACTOR = 2>
typedef T& sheaf::pool< T, EXTENSION_FACTOR >::reference_type

A type that behaves as a reference to the container's value type.

Definition at line 84 of file pool.h.

◆ size_type

template<typename T, int EXTENSION_FACTOR = 2>
typedef unsigned long int sheaf::pool< T, EXTENSION_FACTOR >::size_type

An unsigned integral type used to represent sizes and capacities.

Definition at line 115 of file pool.h.

◆ value_type

template<typename T, int EXTENSION_FACTOR = 2>
typedef T sheaf::pool< T, EXTENSION_FACTOR >::value_type

The container's value type.

Definition at line 79 of file pool.h.

Constructor & Destructor Documentation

◆ pool()

template<typename T , int EXTENSION_FACTOR>
sheaf::pool< T, EXTENSION_FACTOR >::pool ( pod_index_type  xub)

Creates an instance with xub upper bound.

Precondition
  • xub >= 0
Postcondition

Definition at line 229 of file pool.impl.h.

References sheaf::invalid_pod_index(), and sheaf::pool< T, EXTENSION_FACTOR >::~pool().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::deallocate().

◆ ~pool()

template<typename T , int EXTENSION_FACTOR>
sheaf::pool< T, EXTENSION_FACTOR >::~pool ( )

Destructor.

Definition at line 258 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::item().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::pool().

Member Function Documentation

◆ allocate()

template<typename T , int EXTENSION_FACTOR>
pod_index_type sheaf::pool< T, EXTENSION_FACTOR >::allocate ( )

Allocate next available index from free list.

Postcondition
  • is_allocated(result)

Definition at line 159 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::deallocate(), sheaf::invalid_pod_index(), and sheaf::is_valid().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::allocated_iterator().

◆ allocated_ct()

template<typename T , int EXTENSION_FACTOR>
int sheaf::pool< T, EXTENSION_FACTOR >::allocated_ct ( ) const

The size of allocated list.

Definition at line 109 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::is_allocated().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::free_list().

◆ allocated_iterator()

template<typename T , int EXTENSION_FACTOR>
index_iterator sheaf::pool< T, EXTENSION_FACTOR >::allocated_iterator ( ) const

An iterator over allocated items in the pool.

Postcondition

Definition at line 139 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::allocate().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::is_allocated().

◆ deallocate()

template<typename T , int EXTENSION_FACTOR>
void sheaf::pool< T, EXTENSION_FACTOR >::deallocate ( pod_index_type  xindex)

Deallocate item at xindex.

Precondition
  • is_allocated(xindex)
Postcondition
  • !is_allocated(xindex)

Definition at line 200 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::pool().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::allocate().

◆ free_ct()

template<typename T , int EXTENSION_FACTOR>
int sheaf::pool< T, EXTENSION_FACTOR >::free_ct ( ) const

The size of free list.

Definition at line 93 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::free_list().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::index_in_bounds().

◆ free_list()

template<typename T , int EXTENSION_FACTOR>
pod_index_type sheaf::pool< T, EXTENSION_FACTOR >::free_list ( ) const

The head of the free list.

Definition at line 101 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::allocated_ct().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::free_ct().

◆ index_in_bounds()

template<typename T , int EXTENSION_FACTOR>
bool sheaf::pool< T, EXTENSION_FACTOR >::index_in_bounds ( pod_index_type  xindex) const

True if xindex is in bounds.

Definition at line 85 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::free_ct().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::index_ub().

◆ index_ub()

template<typename T , int EXTENSION_FACTOR>
pod_index_type sheaf::pool< T, EXTENSION_FACTOR >::index_ub ( ) const

The upper bound on the index for members of the pool.

Postcondition
  • result >= 0

Definition at line 65 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::index_in_bounds().

Referenced by sheaf::deep_size(), and sheaf::pool< T, EXTENSION_FACTOR >::invariant().

◆ invariant()

template<typename T , int EXTENSION_FACTOR>
bool sheaf::pool< T, EXTENSION_FACTOR >::invariant ( ) const

Class invariant.

Invariant
  • _pool.ub() == _is_allocated->ub()
Todo:
elaborate pool::invariant()

Definition at line 49 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::index_ub().

◆ is_allocated()

template<typename T , int EXTENSION_FACTOR>
bool sheaf::pool< T, EXTENSION_FACTOR >::is_allocated ( pod_index_type  xindex) const

True if xindex is allocated.

Precondition
  • index_in_bounds(xindex)

Definition at line 117 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::allocated_iterator().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::allocated_ct().

◆ item()

template<typename T , int EXTENSION_FACTOR>
T & sheaf::pool< T, EXTENSION_FACTOR >::item ( pod_index_type  xindex)

A pointer to the pool item at xindex.

Precondition
  • index_in_bounds(xindex)

Definition at line 278 of file pool.impl.h.

References sheaf::pool< T, EXTENSION_FACTOR >::operator[]().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::~pool().

◆ operator[]()

template<typename T , int EXTENSION_FACTOR>
T & sheaf::pool< T, EXTENSION_FACTOR >::operator[] ( pod_index_type  xindex)

A reference to the pool item at xindex.

Precondition
  • index_in_bounds(xindex)

Definition at line 297 of file pool.impl.h.

References sheaf::invalid_pod_index(), sheaf::is_valid(), and sheaf::pool< T, EXTENSION_FACTOR >::print().

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::item().

◆ print() [1/2]

template<typename T , int EXTENSION_FACTOR>
void sheaf::pool< T, EXTENSION_FACTOR >::print ( ) const

Prints the data members of this on cout. Intended for use debugging.

Definition at line 409 of file pool.impl.h.

Referenced by sheaf::pool< T, EXTENSION_FACTOR >::operator[]().

◆ print() [2/2]

template<typename T , int EXTENSION_FACTOR>
void sheaf::pool< T, EXTENSION_FACTOR >::print ( std::ostream &  out) const

Prints the data members of this on cout. Intended for use debugging.

Definition at line 417 of file pool.impl.h.

Friends And Related Function Documentation

◆ deep_size

template<typename T, int EXTENSION_FACTOR = 2>
size_t deep_size ( const pool< T, EXTENSION_FACTOR > &  xpool,
bool  xinclude_shallow 
)
friend

The deep size of the referenced object of type pool<T, int>.

Postcondition
  • result >= 0

Definition at line 453 of file pool.impl.h.


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