Rosetta  2020.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
utility::graph::ArrayPool< T > Class Template Reference

#include <ArrayPool.hh>

Inheritance diagram for utility::graph::ArrayPool< T >:
Inheritance graph
[legend]

Public Member Functions

 ArrayPool ()
 Creation and destruction. More...
 
 ArrayPool (platform::Size block_size)
 Constructor with block-size specification. More...
 
 ArrayPool (platform::Size block_size, platform::Size array_size)
 Constructor with block-size and array-size specification. More...
 
 ~ArrayPool () override
 
platform::Size array_size () const
 Methods to read information about the pool size. More...
 
platform::Size block_size () const
 Returns the number of arrays to allocate in each block. More...
 
platform::Size footprint () const
 Returns the number of bytes occupied by all allocated and not-yet allocated arrays. More...
 
void set_array_size (platform::Size size)
 Methods to modify the size of the pool. More...
 
void set_block_size (platform::Size size)
 
platform::Size nblocks () const
 Return the number of allocated array blocks. More...
 
platform::Size nallocated () const
 Return the number of allocated arrays. If this were multiplied by the array_size_, then you'd have the amount of space spent representing the T arrays but you wouldn't have the amount of space spent representing the negative space linked list. More...
 
platform::Size noutstanding () const
 Return the number of allocated arrays that have been requested by the user and are now "outstanding" in that they have to be returned before the array pool may be deleted. More...
 
bool empty () const
 
ArrayPoolElement< Tnew_array ()
 Methods for allocating and deallocating arrays from this pool. More...
 
void deallocate_array (ArrayPoolElement< T > const &element)
 Free an ArrayPoolElement to the pool. The element is invalid after this call completes. More...
 
- Public Member Functions inherited from utility::pointer::ReferenceCount
 ReferenceCount ()
 Default constructor. More...
 
virtual ~ReferenceCount ()
 

Private Member Functions

void create_new_block ()
 Add a new block to the pool and add the elements of this block to the negative space singly linked list. The block sizes and the array sizes must be set before this method is called and, so long as the ArrayPool is not empty, these sizes may not be altered. More...
 
void clear ()
 Deallocate all the allocated blocks. The pool must be empty before this should be called or dangling references are likely. More...
 
bool mine (NegSpaceElement< T > const *neg_element) const
 Determine if a given pointer to a negative-space element belongs to this pool. The compiler cannot ensure that when a ArrayPoolElement is handed to the deallocate_array method that it belongs to the pool being invoked upon. More...
 

Private Attributes

platform::Size block_size_
 
platform::Size array_size_
 
platform::Size nblocks_
 
platform::Size nnegative_
 
NegSpaceElement< Tneg_begin_
 
std::list< NegSpaceElement< T > * > neg_space_blocks_
 
std::list< T * > array_blocks_
 

Additional Inherited Members

- Public Types inherited from utility::pointer::ReferenceCount
typedef platform::Size Size
 
typedef platform::Size size_type
 

Constructor & Destructor Documentation

template<class T >
utility::graph::ArrayPool< T >::ArrayPool ( )
inline

Creation and destruction.

Default constructor uses a block size of 32

template<class T >
utility::graph::ArrayPool< T >::ArrayPool ( platform::Size  block_size)
inline

Constructor with block-size specification.

template<class T >
utility::graph::ArrayPool< T >::ArrayPool ( platform::Size  block_size,
platform::Size  array_size 
)
inline

Constructor with block-size and array-size specification.

template<class T >
utility::graph::ArrayPool< T >::~ArrayPool ( )
inlineoverride

Member Function Documentation

template<class T >
platform::Size utility::graph::ArrayPool< T >::array_size ( ) const
inline

Methods to read information about the pool size.

Returns the size of each array to be allocated.

References utility::graph::ArrayPool< T >::array_size_.

template<class T >
platform::Size utility::graph::ArrayPool< T >::block_size ( ) const
inline

Returns the number of arrays to allocate in each block.

References utility::graph::ArrayPool< T >::block_size_.

template<class T >
void utility::graph::ArrayPool< T >::clear ( )
inlineprivate
template<class T >
void utility::graph::ArrayPool< T >::create_new_block ( )
inlineprivate

Add a new block to the pool and add the elements of this block to the negative space singly linked list. The block sizes and the array sizes must be set before this method is called and, so long as the ArrayPool is not empty, these sizes may not be altered.

This array pool supports, but does not recommend using, array sizes of 0. The resulting ArrayPoolElements have Array0 objecst that point at null, and therefore, should never be dereferenced. However, there is nothing inherrently wrong with pointing at null, or with having an array that is never examined, and so it is supported.

References utility::graph::ArrayPool< T >::array_blocks_, utility::graph::ArrayPool< T >::array_size_, utility::graph::block_allocation_error_message(), utility::graph::ArrayPool< T >::block_size_, debug_assert, test.T200_Scoring::ii, utility::graph::ArrayPool< T >::nblocks_, utility::graph::ArrayPool< T >::neg_begin_, utility::graph::ArrayPool< T >::neg_space_blocks_, utility::graph::neg_space_element_allocation_error_message(), utility::graph::ArrayPool< T >::nnegative_, utility::graph::NegSpaceElement< T >::set_array(), utility::graph::NegSpaceElement< T >::set_next(), and utility_exit_with_message.

Referenced by utility::graph::ArrayPool< T >::new_array().

template<class T >
void utility::graph::ArrayPool< T >::deallocate_array ( ArrayPoolElement< T > const &  element)
inline
template<class T >
bool utility::graph::ArrayPool< T >::empty ( ) const
inline
template<class T >
platform::Size utility::graph::ArrayPool< T >::footprint ( ) const
inline

Returns the number of bytes occupied by all allocated and not-yet allocated arrays.

Approximate the cost of each list element in the two std::lists as 4 times the cost of a pointer.

References utility::graph::ArrayPool< T >::array_size_, utility::graph::ArrayPool< T >::block_size_, and utility::graph::ArrayPool< T >::nblocks_.

template<class T >
bool utility::graph::ArrayPool< T >::mine ( NegSpaceElement< T > const *  neg_element) const
inlineprivate

Determine if a given pointer to a negative-space element belongs to this pool. The compiler cannot ensure that when a ArrayPoolElement is handed to the deallocate_array method that it belongs to the pool being invoked upon.

This method is too slow to include in release builds, but is here to ensure in debug mode that two pools don't accidentally start crossing their pointers and "sharing" data, since that would be disasterous.

References utility::graph::ArrayPool< T >::block_size_, basic::options::OptionKeys::in::file::list, and utility::graph::ArrayPool< T >::neg_space_blocks_.

Referenced by utility::graph::ArrayPool< T >::deallocate_array().

template<class T >
platform::Size utility::graph::ArrayPool< T >::nallocated ( ) const
inline

Return the number of allocated arrays. If this were multiplied by the array_size_, then you'd have the amount of space spent representing the T arrays but you wouldn't have the amount of space spent representing the negative space linked list.

References utility::graph::ArrayPool< T >::block_size_, and utility::graph::ArrayPool< T >::nblocks_.

Referenced by utility::graph::ArrayPool< T >::deallocate_array(), utility::graph::ArrayPool< T >::empty(), and utility::graph::ArrayPool< T >::noutstanding().

template<class T >
platform::Size utility::graph::ArrayPool< T >::nblocks ( ) const
inline

Return the number of allocated array blocks.

References utility::graph::ArrayPool< T >::nblocks_.

template<class T >
ArrayPoolElement< T > utility::graph::ArrayPool< T >::new_array ( )
inline
template<class T >
platform::Size utility::graph::ArrayPool< T >::noutstanding ( ) const
inline

Return the number of allocated arrays that have been requested by the user and are now "outstanding" in that they have to be returned before the array pool may be deleted.

References utility::graph::ArrayPool< T >::nallocated(), and utility::graph::ArrayPool< T >::nnegative_.

template<class T >
void utility::graph::ArrayPool< T >::set_array_size ( platform::Size  size)
inline

Methods to modify the size of the pool.

Set the size of the arrays that the pool is meant to allocate.

The

References utility::graph::ArrayPool< T >::array_size_, utility::graph::ArrayPool< T >::clear(), utility::graph::ArrayPool< T >::empty(), amino_acids::size, and utility_exit_with_message.

template<class T >
void utility::graph::ArrayPool< T >::set_block_size ( platform::Size  size)
inline

Member Data Documentation

template<class T >
std::list< T * > utility::graph::ArrayPool< T >::array_blocks_
private
template<class T >
platform::Size utility::graph::ArrayPool< T >::array_size_
private
template<class T >
platform::Size utility::graph::ArrayPool< T >::block_size_
private
template<class T >
platform::Size utility::graph::ArrayPool< T >::nblocks_
private
template<class T >
NegSpaceElement< T > utility::graph::ArrayPool< T >::neg_begin_
private
template<class T >
std::list< NegSpaceElement< T > * > utility::graph::ArrayPool< T >::neg_space_blocks_
private
template<class T >
platform::Size utility::graph::ArrayPool< T >::nnegative_
private

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