TPIE

2362a60
tpie::linear_memory_base< child_t > Struct Template Reference

Base class of data structures with linear memory usage. More...

#include <tpie/util.h>

Inherited by tpie::internal_stack_vector_base< T, child_t >.

Static Public Member Functions

static memory_size_type memory_usage (memory_size_type size)
 Return the number of bytes required to create a data structure supporting a given number of elements. More...
 
static memory_size_type memory_fits (memory_size_type memory)
 Return the maximum number of elements that can be contained in in the structure when it is allowed to fill a given number of bytes. More...
 

Detailed Description

template<typename child_t>
struct tpie::linear_memory_base< child_t >

Base class of data structures with linear memory usage.

Uses CRTP to defer the definition of memory_coefficient and memory_overhead which must be implemented in the subclass.

Defines two static methods, memory_usage and memory_fits, that determine the amount of memory used and the number of items for a given memory amount, respectively.

Definition at line 73 of file util.h.

Member Function Documentation

template<typename child_t>
static memory_size_type tpie::linear_memory_base< child_t >::memory_fits ( memory_size_type  memory)
inlinestatic

Return the maximum number of elements that can be contained in in the structure when it is allowed to fill a given number of bytes.

Parameters
memoryThe number of bytes the structure is allowed to occupy
Returns
The number of elements that will fit in the structure

Definition at line 93 of file util.h.

93  {
94  return static_cast<memory_size_type>(
95  floor((memory - child_t::memory_overhead()) / child_t::memory_coefficient()));
96  }
template<typename child_t>
static memory_size_type tpie::linear_memory_base< child_t >::memory_usage ( memory_size_type  size)
inlinestatic

Return the number of bytes required to create a data structure supporting a given number of elements.

Parameters
sizeThe number of elements to support
Returns
The amount of memory required in bytes

Definition at line 81 of file util.h.

81  {
82  return static_cast<memory_size_type>(
83  floor(static_cast<double>(size) * child_t::memory_coefficient() + child_t::memory_overhead()));
84  }

The documentation for this struct was generated from the following file: